Class: Brigit::HopCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/brigit/commands/hop_command.rb

Instance Attribute Summary

Attributes inherited from Command

#args

Instance Method Summary collapse

Methods inherited from Command

help, #initialize

Methods included from Pretending

#pretend!

Methods included from Fallible

#fail

Methods included from Listable

included

Constructor Details

This class inherits a constructor from Brigit::Command

Instance Method Details

#runObject



7
8
9
10
11
12
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
# File 'lib/brigit/commands/hop_command.rb', line 7

def run
  ref = default_ref
  super do |parser|
    parser.on('-r TREE-ISH', '--ref', "(default: `#{ref}')") do |treeish|
      ref = treeish
    end
    add_pretend_to parser
  end
  check_url!
  changed = []
  errors = []
  submodules.each do |path, parent|
    Dir.chdir path do
      say "cd #{path}"
      if clean?
        sh 'git pull origin master'
        sh "git checkout '#{ref}'"
        changed << parent
      else
        say "Working directory isn't clean, skipping"
        errors << path
      end
    end
  end
  if changed.any?
    say "---\nPlease check and commit the following parent repositories:\n#{format_list changed}"
  end
  if errors.any?
    say "---\nCould not update the following locations:\n#{format_list errors}"
  end
end