Class: MultiRepo::UpdateCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/multirepo/commands/update-command.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#ensure_in_work_tree, #ensure_multirepo_enabled, #ensure_multirepo_tracked, #install_hooks, #multirepo_enabled_dependencies, report_error, #uninstall_hooks, #update_gitconfig

Constructor Details

#initialize(argv) ⇒ UpdateCommand

Returns a new instance of UpdateCommand.



25
26
27
28
29
30
31
32
# File 'lib/multirepo/commands/update-command.rb', line 25

def initialize(argv)
  @repo_selection = RepoSelection.new(argv)
  @commit = argv.flag?("commit")
  @force = argv.flag?("force")
  @diff = argv.flag?("diff", true)
  @message = argv.shift_argument
  super
end

Class Method Details

.optionsObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/multirepo/commands/update-command.rb', line 13

def self.options
  [
    ['[--all]', 'Update the main repository and all dependencies.'],
    ['[--main]', 'Update the main repository.'],
    ['[--deps]', 'Update dependencies.'],
    ['[--force]', 'Update the tracking files even if dependencies contain uncommitted changes.'],
    ['[--commit]', 'Commit the tracking files after updating them.'],
    ['[--no-diff]', 'Don\'t show lock file diff(s) after updating.'],
    ['<message>', 'A commit message for the update (what changed in the dependencies)']
  ].concat(super)
end

Instance Method Details

#commit_tracking_files(path) ⇒ Object



105
106
107
108
109
# File 'lib/multirepo/commands/update-command.rb', line 105

def commit_tracking_files(path)
  tracking_files = TrackingFiles.new(path)
  committed = tracking_files.commit(@message)
  Console.log_info("Committed tracking files") if committed
end

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/multirepo/commands/update-command.rb', line 40

def run
  ensure_in_work_tree
  ensure_multirepo_enabled
  
  dependencies_clean = Utils.dependencies_clean?(ConfigFile.new(".").load_entries)
  if dependencies_clean || @force
    update_tracking_files_step(@repo_selection.value)
  else
    fail MultiRepoException, "Can't update because not all dependencies are clean"
  end
  
  Console.log_step("Done!")
end

#show_diff(path) ⇒ Object



111
112
113
# File 'lib/multirepo/commands/update-command.rb', line 111

def show_diff(path)
  GitRunner.run_as_system(path, "diff .multirepo.lock")
end

#update_dependenciesObject



69
70
71
72
73
74
75
76
77
# File 'lib/multirepo/commands/update-command.rb', line 69

def update_dependencies
  any_changed = false
  Performer.depth_ordered_dependencies.each do |dependency|
    path = dependency.config_entry.path
    name = dependency.config_entry.name
    any_changed |= update_one(path, name) if Utils.multirepo_enabled?(path)
  end
  return any_changed
end

#update_mainObject



79
80
81
# File 'lib/multirepo/commands/update-command.rb', line 79

def update_main
  update_one(".", "main repo")
end

#update_one(path, name) ⇒ Object



83
84
85
86
87
88
# File 'lib/multirepo/commands/update-command.rb', line 83

def update_one(path, name)
  updated = update_tracking_files(path, name)
  show_diff(path) if updated && @diff
  commit_tracking_files(path) if @commit
  return updated
end

#update_tracking_files(path, name) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/multirepo/commands/update-command.rb', line 90

def update_tracking_files(path, name)
  Console.log_substep("Updating tracking files in #{name}")
  
  tracking_files = TrackingFiles.new(path)
  changed = tracking_files.update
  
  if changed
    Console.log_info("Updated tracking files")
  else
    Console.log_info("Tracking files are already up-to-date")
  end
  
  return changed
end

#update_tracking_files_step(repo_selection_value) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/multirepo/commands/update-command.rb', line 54

def update_tracking_files_step(repo_selection_value)
  case repo_selection_value
  when RepoSelection::MAIN
    Console.log_step("Updating main repo...")
    update_main
  when RepoSelection::DEPS
    Console.log_step("Updating dependencies...")
    update_dependencies
  when RepoSelection::ALL
    Console.log_step("Updating main repo and dependencies...")
    update_dependencies
    update_main
  end
end

#validate!Object



34
35
36
37
38
# File 'lib/multirepo/commands/update-command.rb', line 34

def validate!
  super
  help! "You can't provide more than one operation modifier (--deps, --main, etc.)" unless @repo_selection.valid?
  help! "You must provide a commit message" if @commit && !@message
end