Module: Dev::Executables::Commands::Push

Included in:
Dev::Executable
Defined in:
lib/dev/executables/commands/push.rb

Instance Method Summary collapse

Instance Method Details

#push(app = nil, commit_message = nil) ⇒ nil

Esegue il commit e il push del repository dell’app specificata.

Parameters:

  • app (String) (defaults to: nil)

    l’app per cui il push delle modifiche.

  • commit_message (String) (defaults to: nil)

    il messaggio di commit.

Returns:

  • (nil)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dev/executables/commands/push.rb', line 13

def push(app = nil, commit_message = nil)
  if app.present? and commit_message.present?
    @project.current_app = app
    if @project.valid_app?
      Dir.chdir @project.app_folder
      current_branch = `git rev-parse --abbrev-ref HEAD`
      
      print "Preparing to push app "
      print @project.current_app.teal
      print " on branch "
      print current_branch.teal
      puts
      
      print "\tRunning bundler.. "
      exec 'bundle install'
      print "√\n".green

      print "\tCommitting.. "
      exec 'git add .'
      exec "git commit -m \"#{commit_message}\""
      print "√\n".green

      print "\tPushing.. "
      remote_message = exec "git push origin #{current_branch}"
      if remote_message.include?('fatal') or remote_message.include?('rejected')
        print "X\n".red
        puts "\t\tSomething went wrong, take a look at the output from git remote:".indianred
        puts "\t\t#{remote_message.split("\n").map(&:squish).join("\n\t\t")}".indianred
        puts
      else
        print "√\n".green
        puts "\t\tDone. Output from git remote:".cadetblue
        puts "\t\t#{remote_message.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
        puts
      end
    end
  else
    raise Dev::Executable::ExecutionError.new "Wrong command syntax: "\
      "specify an app and a commit message. "\
      "Example: dev push app \"commit message\"."
  end
end