-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate.rb
65 lines (51 loc) · 2.15 KB
/
update.rb
1
2
3
4
5
6
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# @see features/tasks/action.feature
module RepoManager
class Action < Thor
namespace :action
include Thor::Actions
include RepoManager::ThorHelper
class_option :force, :type => :boolean, :desc => "Force overwrite and answer 'yes' to any prompts"
method_option :repos, :type => :string, :desc => "Restrict update to comma delimited list of repo names", :banner => "repo1,repo2"
method_option :message, :type => :string, :desc => "Override 'automatic commit' message"
method_option 'no-push', :type => :boolean, :default => false, :desc => "Force overwrite of existing config file"
desc "update", "run repo add -A, repo commit, and repo push on all modified repos"
def update
initial_filter = options[:repos] ? "--repos=#{options[:repos]}" : ""
output = run("repo status --short --unmodified=HIDE --no-verbose --no-color #{initial_filter}", :capture => true)
case $?.exitstatus
when 0
say 'no changed repos', :green
else
unless output
say "failed to successfully run 'repo status'", :red
exit $?.exitstatus
end
repos = []
output = output.split("\n")
while line = output.shift
st,repo = line.split("\t")
repos << repo
end
filter = repos.join(',')
unless options[:force]
say "Repo(s) '#{filter}' have changed."
unless ask("Add, commit and push them? (y/n)") == 'y'
say "aborting"
exit 0
end
end
say "updating #{filter}"
run "repo add -A --no-verbose --repos #{filter}"
exit $?.exitstatus if ($?.exitstatus > 1)
commit_message = options[:message] || "automatic commit @ #{Time.now}"
run "repo commit --message=#{shell_quote(commit_message)} --no-verbose --repos #{filter}"
exit $?.exitstatus if ($?.exitstatus > 1)
unless options['no-push']
run "repo push --no-verbose --repos #{filter}"
exit $?.exitstatus if ($?.exitstatus > 1)
end
say "update finished", :green
end
end
end
end