git-multirepo 1.0.0.beta56 → 1.0.0.beta57
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +2 -2
- data/.gitbugtraq +3 -3
- data/.gitignore +38 -38
- data/.multirepo.meta +2 -2
- data/.rspec +2 -2
- data/.rubocop.yml +79 -79
- data/CHANGELOG.md +61 -57
- data/Gemfile +4 -4
- data/Gemfile.lock +42 -42
- data/LICENSE +22 -22
- data/README.md +179 -178
- data/Rakefile +1 -1
- data/bin/multi +11 -11
- data/docs/bug-repros/91565510-repro.sh +20 -20
- data/git-multirepo.gemspec +31 -31
- data/lib/git-multirepo.rb +3 -3
- data/lib/multirepo/commands/add-command.rb +51 -51
- data/lib/multirepo/commands/branch-command.rb +82 -82
- data/lib/multirepo/commands/checkout-command.rb +127 -127
- data/lib/multirepo/commands/clone-command.rb +68 -68
- data/lib/multirepo/commands/command.rb +87 -87
- data/lib/multirepo/commands/commands.rb +15 -15
- data/lib/multirepo/commands/do-command.rb +101 -101
- data/lib/multirepo/commands/graph-command.rb +43 -43
- data/lib/multirepo/commands/init-command.rb +121 -121
- data/lib/multirepo/commands/inspect-command.rb +48 -48
- data/lib/multirepo/commands/install-command.rb +161 -161
- data/lib/multirepo/commands/merge-command.rb +249 -249
- data/lib/multirepo/commands/open-command.rb +55 -55
- data/lib/multirepo/commands/remove-command.rb +48 -48
- data/lib/multirepo/commands/uninit-command.rb +18 -18
- data/lib/multirepo/commands/update-command.rb +112 -112
- data/lib/multirepo/config.rb +19 -19
- data/lib/multirepo/files/config-entry.rb +39 -39
- data/lib/multirepo/files/config-file.rb +46 -46
- data/lib/multirepo/files/lock-entry.rb +29 -29
- data/lib/multirepo/files/lock-file.rb +56 -56
- data/lib/multirepo/files/meta-file.rb +41 -41
- data/lib/multirepo/files/tracking-file.rb +9 -9
- data/lib/multirepo/files/tracking-files.rb +47 -47
- data/lib/multirepo/git/branch.rb +32 -32
- data/lib/multirepo/git/change.rb +11 -11
- data/lib/multirepo/git/commit.rb +7 -7
- data/lib/multirepo/git/git-runner.rb +56 -56
- data/lib/multirepo/git/git.rb +10 -10
- data/lib/multirepo/git/ref.rb +38 -38
- data/lib/multirepo/git/remote.rb +17 -17
- data/lib/multirepo/git/repo.rb +129 -129
- data/lib/multirepo/hooks/post-commit-hook.rb +23 -23
- data/lib/multirepo/hooks/pre-commit-hook.rb +35 -35
- data/lib/multirepo/info.rb +5 -5
- data/lib/multirepo/logic/dependency.rb +6 -6
- data/lib/multirepo/logic/merge-descriptor.rb +95 -95
- data/lib/multirepo/logic/node.rb +72 -72
- data/lib/multirepo/logic/performer.rb +55 -55
- data/lib/multirepo/logic/repo-selection.rb +25 -25
- data/lib/multirepo/logic/revision-selection.rb +15 -15
- data/lib/multirepo/logic/revision-selector.rb +23 -23
- data/lib/multirepo/multirepo-exception.rb +6 -6
- data/lib/multirepo/output/extra-output.rb +12 -12
- data/lib/multirepo/output/teamcity-extra-output.rb +11 -11
- data/lib/multirepo/utility/console.rb +52 -52
- data/lib/multirepo/utility/popen-runner.rb +27 -27
- data/lib/multirepo/utility/system-runner.rb +14 -14
- data/lib/multirepo/utility/utils.rb +99 -99
- data/lib/multirepo/utility/verbosity.rb +6 -6
- data/resources/.gitconfig +2 -2
- data/resources/post-commit +6 -6
- data/resources/pre-commit +6 -6
- data/spec/integration/init_spec.rb +19 -19
- data/spec/spec_helper.rb +89 -89
- metadata +3 -3
@@ -1,249 +1,249 @@
|
|
1
|
-
require "terminal-table"
|
2
|
-
|
3
|
-
require "multirepo/utility/console"
|
4
|
-
require "multirepo/utility/utils"
|
5
|
-
require "multirepo/logic/node"
|
6
|
-
require "multirepo/logic/revision-selector"
|
7
|
-
require "multirepo/logic/repo-selection"
|
8
|
-
require "multirepo/logic/performer"
|
9
|
-
require "multirepo/logic/merge-descriptor"
|
10
|
-
require "multirepo/files/tracking-files"
|
11
|
-
require "multirepo/commands/update-command"
|
12
|
-
|
13
|
-
module MultiRepo
|
14
|
-
class MergeValidationResult
|
15
|
-
ABORT = 0
|
16
|
-
PROCEED = 1
|
17
|
-
MERGE_UPSTREAM = 2
|
18
|
-
|
19
|
-
attr_accessor :outcome
|
20
|
-
attr_accessor :message
|
21
|
-
end
|
22
|
-
|
23
|
-
class MergeCommand < Command
|
24
|
-
self.command = "merge"
|
25
|
-
self.summary = "Performs a git merge on all dependencies and the main repo, in the proper order."
|
26
|
-
|
27
|
-
def self.options
|
28
|
-
[
|
29
|
-
['<refname>', 'The main repo tag, branch or commit id to merge.'],
|
30
|
-
['[--latest]', 'Merge the HEAD of each stored dependency branch instead of the commits recorded in the lock file.'],
|
31
|
-
['[--exact]', 'Merge the exact specified ref for each repo, regardless of what\'s stored in the lock file.']
|
32
|
-
].concat(super)
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(argv)
|
36
|
-
@ref_name = argv.shift_argument
|
37
|
-
@checkout_latest = argv.flag?("latest")
|
38
|
-
@checkout_exact = argv.flag?("exact")
|
39
|
-
super
|
40
|
-
end
|
41
|
-
|
42
|
-
def validate!
|
43
|
-
super
|
44
|
-
help! "You must specify a ref to merge" unless @ref_name
|
45
|
-
unless Utils.only_one_true?(@checkout_latest, @checkout_exact)
|
46
|
-
help! "You can't provide more than one operation modifier (--latest, --exact, etc.)"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def run
|
51
|
-
ensure_in_work_tree
|
52
|
-
ensure_multirepo_enabled
|
53
|
-
|
54
|
-
# Find out the checkout mode based on command-line options
|
55
|
-
mode = RevisionSelector.mode_for_args(@checkout_latest, @checkout_exact)
|
56
|
-
|
57
|
-
strategy_name = RevisionSelection.name_for_mode(mode)
|
58
|
-
Console.log_step("Merging #{@ref_name} with '#{strategy_name}' strategy...")
|
59
|
-
|
60
|
-
main_repo = Repo.new(".")
|
61
|
-
|
62
|
-
# Keep the initial revision because we're going to need to come back to it later
|
63
|
-
initial_revision = main_repo.current_revision
|
64
|
-
|
65
|
-
begin
|
66
|
-
merge_core(main_repo, initial_revision, mode)
|
67
|
-
rescue MultiRepoException => e
|
68
|
-
# Revert to the initial revision only if necessary
|
69
|
-
unless main_repo.current_revision == initial_revision
|
70
|
-
Console.log_warning("Restoring working copy to #{initial_revision}")
|
71
|
-
main_repo.checkout(initial_revision)
|
72
|
-
end
|
73
|
-
raise e
|
74
|
-
end
|
75
|
-
|
76
|
-
Console.log_step("Done!")
|
77
|
-
end
|
78
|
-
|
79
|
-
def merge_core(main_repo, initial_revision, mode)
|
80
|
-
config_file = ConfigFile.new(".")
|
81
|
-
|
82
|
-
# Ensure the main repo is clean
|
83
|
-
fail MultiRepoException, "Main repo is not clean; merge aborted" unless main_repo.clean?
|
84
|
-
|
85
|
-
# Ensure dependencies are clean
|
86
|
-
unless Utils.dependencies_clean?(config_file.load_entries)
|
87
|
-
fail MultiRepoException, "Dependencies are not clean; merge aborted"
|
88
|
-
end
|
89
|
-
|
90
|
-
ref_name = @ref_name
|
91
|
-
descriptors = nil
|
92
|
-
loop do
|
93
|
-
# Gather information about the merges that would occur
|
94
|
-
descriptors = build_merge(main_repo, initial_revision, ref_name, mode)
|
95
|
-
|
96
|
-
# Preview merge operations in the console
|
97
|
-
preview_merge(descriptors, mode, ref_name)
|
98
|
-
|
99
|
-
# Validate merge operations
|
100
|
-
result = ensure_merge_valid(descriptors)
|
101
|
-
|
102
|
-
case result.outcome
|
103
|
-
when MergeValidationResult::ABORT
|
104
|
-
fail MultiRepoException, result.message
|
105
|
-
when MergeValidationResult::PROCEED
|
106
|
-
fail MultiRepoException, "Merge aborted" unless Console.ask("Proceed?")
|
107
|
-
Console.log_warning(result.message) if result.message
|
108
|
-
break
|
109
|
-
when MergeValidationResult::MERGE_UPSTREAM
|
110
|
-
Console.log_warning(result.message)
|
111
|
-
fail MultiRepoException, "Merge aborted" unless Console.ask("Merge upstream instead of local branches?")
|
112
|
-
# TODO: Modify operations!
|
113
|
-
fail MultiRepoException, "Fallback behavior not implemented. Please merge manually."
|
114
|
-
next
|
115
|
-
end
|
116
|
-
|
117
|
-
fail MultiRepoException, "Merge aborted" unless Console.ask("Proceed?")
|
118
|
-
end
|
119
|
-
|
120
|
-
Console.log_step("Performing merge...")
|
121
|
-
|
122
|
-
all_succeeded = perform_merges(descriptors)
|
123
|
-
ask_tracking_files_update(all_succeeded)
|
124
|
-
end
|
125
|
-
|
126
|
-
def build_merge(main_repo, initial_revision, ref_name, mode)
|
127
|
-
# List dependencies prior to checkout so that we can compare them later
|
128
|
-
our_dependencies = Performer.dependencies
|
129
|
-
|
130
|
-
# Checkout the specified main repo ref to find out which dependency refs to merge
|
131
|
-
commit_id = Ref.new(main_repo, ref_name).commit_id # Checkout in floating HEAD
|
132
|
-
Performer.perform_main_repo_checkout(main_repo, commit_id, false, "Checked out main repo '#{ref_name}' to inspect to-merge dependencies")
|
133
|
-
|
134
|
-
# List dependencies for the ref we're trying to merge
|
135
|
-
their_dependencies = Performer.dependencies
|
136
|
-
|
137
|
-
# Checkout the initial revision ASAP
|
138
|
-
Performer.perform_main_repo_checkout(main_repo, initial_revision, false, "Checked out initial main repo revision '#{initial_revision}'")
|
139
|
-
|
140
|
-
# Auto-merge would be too complex to implement (due to lots of edge cases)
|
141
|
-
# if the specified ref does not have the same dependencies. Better perform a manual merge.
|
142
|
-
ensure_dependencies_match(our_dependencies, their_dependencies)
|
143
|
-
|
144
|
-
# Create a merge descriptor for each would-be merge as well as the main repo.
|
145
|
-
# This step MUST be performed in OUR revision for the merge descriptors to be correct!
|
146
|
-
descriptors = build_dependency_merge_descriptors(our_dependencies, their_dependencies, ref_name, mode)
|
147
|
-
descriptors.push(MergeDescriptor.new("Main Repo", main_repo, initial_revision, ref_name))
|
148
|
-
|
149
|
-
return descriptors
|
150
|
-
end
|
151
|
-
|
152
|
-
def build_dependency_merge_descriptors(our_dependencies, their_dependencies, ref_name, mode)
|
153
|
-
descriptors = []
|
154
|
-
our_dependencies.zip(their_dependencies).each do |our_dependency, their_dependency|
|
155
|
-
our_revision = our_dependency.config_entry.repo.current_revision
|
156
|
-
|
157
|
-
their_revision = RevisionSelector.revision_for_mode(mode, ref_name, their_dependency.lock_entry)
|
158
|
-
their_name = their_dependency.config_entry.name
|
159
|
-
their_repo = their_dependency.config_entry.repo
|
160
|
-
|
161
|
-
descriptor = MergeDescriptor.new(their_name, their_repo, our_revision, their_revision)
|
162
|
-
|
163
|
-
descriptors.push(descriptor)
|
164
|
-
end
|
165
|
-
return descriptors
|
166
|
-
end
|
167
|
-
|
168
|
-
def ensure_dependencies_match(our_dependencies, their_dependencies)
|
169
|
-
our_dependencies.zip(their_dependencies).each do |our_dependency, their_dependency|
|
170
|
-
if their_dependency.nil? || their_dependency.config_entry.id != our_dependency.config_entry.id
|
171
|
-
fail MultiRepoException, "Dependencies differ, please merge manually"
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
if their_dependencies.count > our_dependencies.count
|
176
|
-
fail MultiRepoException, "There are more dependencies in the specified ref, please merge manually"
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def preview_merge(descriptors, mode, ref_name)
|
181
|
-
Console.log_info("Merging would #{message_for_mode(mode, ref_name)}:")
|
182
|
-
|
183
|
-
table = Terminal::Table.new do |t|
|
184
|
-
descriptors.reverse.each_with_index do |descriptor, index|
|
185
|
-
t.add_row [descriptor.name.bold, descriptor.merge_description, descriptor.upstream_description]
|
186
|
-
t.add_separator unless index == descriptors.count - 1
|
187
|
-
end
|
188
|
-
end
|
189
|
-
puts table
|
190
|
-
end
|
191
|
-
|
192
|
-
def ensure_merge_valid(descriptors)
|
193
|
-
outcome = MergeValidationResult.new
|
194
|
-
outcome.outcome = MergeValidationResult::PROCEED
|
195
|
-
|
196
|
-
if descriptors.any? { |d| d.state == TheirState::LOCAL_NO_UPSTREAM }
|
197
|
-
outcome.message = "Some branches are not remote-tracking! Please review the merge operations above."
|
198
|
-
elsif descriptors.any? { |d| d.state == TheirState::LOCAL_UPSTREAM_DIVERGED }
|
199
|
-
outcome.outcome = MergeValidationResult::ABORT
|
200
|
-
outcome.message = "Some upstream branches have diverged. This warrants a manual merge!"
|
201
|
-
elsif descriptors.any? { |d| d.state == TheirState::LOCAL_OUTDATED }
|
202
|
-
outcome.outcome = MergeValidationResult::MERGE_UPSTREAM
|
203
|
-
outcome.message = "Some local branches are outdated"
|
204
|
-
end
|
205
|
-
|
206
|
-
return outcome
|
207
|
-
end
|
208
|
-
|
209
|
-
def perform_merges(descriptors)
|
210
|
-
success = true
|
211
|
-
descriptors.each do |descriptor|
|
212
|
-
Console.log_substep("#{descriptor.name} : Merging #{descriptor.their_revision} into #{descriptor.our_revision}...")
|
213
|
-
GitRunner.run_as_system(descriptor.repo.path, "merge #{descriptor.their_revision}")
|
214
|
-
success &= GitRunner.last_command_succeeded
|
215
|
-
end
|
216
|
-
|
217
|
-
if success
|
218
|
-
Console.log_info("All merges performed successfully!")
|
219
|
-
else
|
220
|
-
Console.log_warning("Some merge operations failed. Please review the above.")
|
221
|
-
end
|
222
|
-
|
223
|
-
return success
|
224
|
-
end
|
225
|
-
|
226
|
-
def ask_tracking_files_update(all_merges_succeeded)
|
227
|
-
unless all_merges_succeeded
|
228
|
-
Console.log_warning("Perform a 'multi update' after resolving merge conflicts to ensure lock file contents are valid")
|
229
|
-
return
|
230
|
-
end
|
231
|
-
|
232
|
-
return unless Console.ask("Update main repo tracking files? (important for continuous integration)")
|
233
|
-
|
234
|
-
update_command = UpdateCommand.new(CLAide::ARGV.new(["--commit", "--diff"]))
|
235
|
-
update_command.update_tracking_files_step(RepoSelection::MAIN)
|
236
|
-
end
|
237
|
-
|
238
|
-
def message_for_mode(mode, ref_name)
|
239
|
-
case mode
|
240
|
-
when RevisionSelection::AS_LOCK
|
241
|
-
"merge specific commits as stored in the lock file for main repo revision #{ref_name}"
|
242
|
-
when RevisionSelection::LATEST
|
243
|
-
"merge each branch as stored in the lock file of main repo revision #{ref_name}"
|
244
|
-
when RevisionSelection::EXACT
|
245
|
-
"merge #{ref_name} for each repository, ignoring the contents of the lock file"
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
1
|
+
require "terminal-table"
|
2
|
+
|
3
|
+
require "multirepo/utility/console"
|
4
|
+
require "multirepo/utility/utils"
|
5
|
+
require "multirepo/logic/node"
|
6
|
+
require "multirepo/logic/revision-selector"
|
7
|
+
require "multirepo/logic/repo-selection"
|
8
|
+
require "multirepo/logic/performer"
|
9
|
+
require "multirepo/logic/merge-descriptor"
|
10
|
+
require "multirepo/files/tracking-files"
|
11
|
+
require "multirepo/commands/update-command"
|
12
|
+
|
13
|
+
module MultiRepo
|
14
|
+
class MergeValidationResult
|
15
|
+
ABORT = 0
|
16
|
+
PROCEED = 1
|
17
|
+
MERGE_UPSTREAM = 2
|
18
|
+
|
19
|
+
attr_accessor :outcome
|
20
|
+
attr_accessor :message
|
21
|
+
end
|
22
|
+
|
23
|
+
class MergeCommand < Command
|
24
|
+
self.command = "merge"
|
25
|
+
self.summary = "Performs a git merge on all dependencies and the main repo, in the proper order."
|
26
|
+
|
27
|
+
def self.options
|
28
|
+
[
|
29
|
+
['<refname>', 'The main repo tag, branch or commit id to merge.'],
|
30
|
+
['[--latest]', 'Merge the HEAD of each stored dependency branch instead of the commits recorded in the lock file.'],
|
31
|
+
['[--exact]', 'Merge the exact specified ref for each repo, regardless of what\'s stored in the lock file.']
|
32
|
+
].concat(super)
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(argv)
|
36
|
+
@ref_name = argv.shift_argument
|
37
|
+
@checkout_latest = argv.flag?("latest")
|
38
|
+
@checkout_exact = argv.flag?("exact")
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def validate!
|
43
|
+
super
|
44
|
+
help! "You must specify a ref to merge" unless @ref_name
|
45
|
+
unless Utils.only_one_true?(@checkout_latest, @checkout_exact)
|
46
|
+
help! "You can't provide more than one operation modifier (--latest, --exact, etc.)"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def run
|
51
|
+
ensure_in_work_tree
|
52
|
+
ensure_multirepo_enabled
|
53
|
+
|
54
|
+
# Find out the checkout mode based on command-line options
|
55
|
+
mode = RevisionSelector.mode_for_args(@checkout_latest, @checkout_exact)
|
56
|
+
|
57
|
+
strategy_name = RevisionSelection.name_for_mode(mode)
|
58
|
+
Console.log_step("Merging #{@ref_name} with '#{strategy_name}' strategy...")
|
59
|
+
|
60
|
+
main_repo = Repo.new(".")
|
61
|
+
|
62
|
+
# Keep the initial revision because we're going to need to come back to it later
|
63
|
+
initial_revision = main_repo.current_revision
|
64
|
+
|
65
|
+
begin
|
66
|
+
merge_core(main_repo, initial_revision, mode)
|
67
|
+
rescue MultiRepoException => e
|
68
|
+
# Revert to the initial revision only if necessary
|
69
|
+
unless main_repo.current_revision == initial_revision
|
70
|
+
Console.log_warning("Restoring working copy to #{initial_revision}")
|
71
|
+
main_repo.checkout(initial_revision)
|
72
|
+
end
|
73
|
+
raise e
|
74
|
+
end
|
75
|
+
|
76
|
+
Console.log_step("Done!")
|
77
|
+
end
|
78
|
+
|
79
|
+
def merge_core(main_repo, initial_revision, mode)
|
80
|
+
config_file = ConfigFile.new(".")
|
81
|
+
|
82
|
+
# Ensure the main repo is clean
|
83
|
+
fail MultiRepoException, "Main repo is not clean; merge aborted" unless main_repo.clean?
|
84
|
+
|
85
|
+
# Ensure dependencies are clean
|
86
|
+
unless Utils.dependencies_clean?(config_file.load_entries)
|
87
|
+
fail MultiRepoException, "Dependencies are not clean; merge aborted"
|
88
|
+
end
|
89
|
+
|
90
|
+
ref_name = @ref_name
|
91
|
+
descriptors = nil
|
92
|
+
loop do
|
93
|
+
# Gather information about the merges that would occur
|
94
|
+
descriptors = build_merge(main_repo, initial_revision, ref_name, mode)
|
95
|
+
|
96
|
+
# Preview merge operations in the console
|
97
|
+
preview_merge(descriptors, mode, ref_name)
|
98
|
+
|
99
|
+
# Validate merge operations
|
100
|
+
result = ensure_merge_valid(descriptors)
|
101
|
+
|
102
|
+
case result.outcome
|
103
|
+
when MergeValidationResult::ABORT
|
104
|
+
fail MultiRepoException, result.message
|
105
|
+
when MergeValidationResult::PROCEED
|
106
|
+
fail MultiRepoException, "Merge aborted" unless Console.ask("Proceed?")
|
107
|
+
Console.log_warning(result.message) if result.message
|
108
|
+
break
|
109
|
+
when MergeValidationResult::MERGE_UPSTREAM
|
110
|
+
Console.log_warning(result.message)
|
111
|
+
fail MultiRepoException, "Merge aborted" unless Console.ask("Merge upstream instead of local branches?")
|
112
|
+
# TODO: Modify operations!
|
113
|
+
fail MultiRepoException, "Fallback behavior not implemented. Please merge manually."
|
114
|
+
next
|
115
|
+
end
|
116
|
+
|
117
|
+
fail MultiRepoException, "Merge aborted" unless Console.ask("Proceed?")
|
118
|
+
end
|
119
|
+
|
120
|
+
Console.log_step("Performing merge...")
|
121
|
+
|
122
|
+
all_succeeded = perform_merges(descriptors)
|
123
|
+
ask_tracking_files_update(all_succeeded)
|
124
|
+
end
|
125
|
+
|
126
|
+
def build_merge(main_repo, initial_revision, ref_name, mode)
|
127
|
+
# List dependencies prior to checkout so that we can compare them later
|
128
|
+
our_dependencies = Performer.dependencies
|
129
|
+
|
130
|
+
# Checkout the specified main repo ref to find out which dependency refs to merge
|
131
|
+
commit_id = Ref.new(main_repo, ref_name).commit_id # Checkout in floating HEAD
|
132
|
+
Performer.perform_main_repo_checkout(main_repo, commit_id, false, "Checked out main repo '#{ref_name}' to inspect to-merge dependencies")
|
133
|
+
|
134
|
+
# List dependencies for the ref we're trying to merge
|
135
|
+
their_dependencies = Performer.dependencies
|
136
|
+
|
137
|
+
# Checkout the initial revision ASAP
|
138
|
+
Performer.perform_main_repo_checkout(main_repo, initial_revision, false, "Checked out initial main repo revision '#{initial_revision}'")
|
139
|
+
|
140
|
+
# Auto-merge would be too complex to implement (due to lots of edge cases)
|
141
|
+
# if the specified ref does not have the same dependencies. Better perform a manual merge.
|
142
|
+
ensure_dependencies_match(our_dependencies, their_dependencies)
|
143
|
+
|
144
|
+
# Create a merge descriptor for each would-be merge as well as the main repo.
|
145
|
+
# This step MUST be performed in OUR revision for the merge descriptors to be correct!
|
146
|
+
descriptors = build_dependency_merge_descriptors(our_dependencies, their_dependencies, ref_name, mode)
|
147
|
+
descriptors.push(MergeDescriptor.new("Main Repo", main_repo, initial_revision, ref_name))
|
148
|
+
|
149
|
+
return descriptors
|
150
|
+
end
|
151
|
+
|
152
|
+
def build_dependency_merge_descriptors(our_dependencies, their_dependencies, ref_name, mode)
|
153
|
+
descriptors = []
|
154
|
+
our_dependencies.zip(their_dependencies).each do |our_dependency, their_dependency|
|
155
|
+
our_revision = our_dependency.config_entry.repo.current_revision
|
156
|
+
|
157
|
+
their_revision = RevisionSelector.revision_for_mode(mode, ref_name, their_dependency.lock_entry)
|
158
|
+
their_name = their_dependency.config_entry.name
|
159
|
+
their_repo = their_dependency.config_entry.repo
|
160
|
+
|
161
|
+
descriptor = MergeDescriptor.new(their_name, their_repo, our_revision, their_revision)
|
162
|
+
|
163
|
+
descriptors.push(descriptor)
|
164
|
+
end
|
165
|
+
return descriptors
|
166
|
+
end
|
167
|
+
|
168
|
+
def ensure_dependencies_match(our_dependencies, their_dependencies)
|
169
|
+
our_dependencies.zip(their_dependencies).each do |our_dependency, their_dependency|
|
170
|
+
if their_dependency.nil? || their_dependency.config_entry.id != our_dependency.config_entry.id
|
171
|
+
fail MultiRepoException, "Dependencies differ, please merge manually"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
if their_dependencies.count > our_dependencies.count
|
176
|
+
fail MultiRepoException, "There are more dependencies in the specified ref, please merge manually"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def preview_merge(descriptors, mode, ref_name)
|
181
|
+
Console.log_info("Merging would #{message_for_mode(mode, ref_name)}:")
|
182
|
+
|
183
|
+
table = Terminal::Table.new do |t|
|
184
|
+
descriptors.reverse.each_with_index do |descriptor, index|
|
185
|
+
t.add_row [descriptor.name.bold, descriptor.merge_description, descriptor.upstream_description]
|
186
|
+
t.add_separator unless index == descriptors.count - 1
|
187
|
+
end
|
188
|
+
end
|
189
|
+
puts table
|
190
|
+
end
|
191
|
+
|
192
|
+
def ensure_merge_valid(descriptors)
|
193
|
+
outcome = MergeValidationResult.new
|
194
|
+
outcome.outcome = MergeValidationResult::PROCEED
|
195
|
+
|
196
|
+
if descriptors.any? { |d| d.state == TheirState::LOCAL_NO_UPSTREAM }
|
197
|
+
outcome.message = "Some branches are not remote-tracking! Please review the merge operations above."
|
198
|
+
elsif descriptors.any? { |d| d.state == TheirState::LOCAL_UPSTREAM_DIVERGED }
|
199
|
+
outcome.outcome = MergeValidationResult::ABORT
|
200
|
+
outcome.message = "Some upstream branches have diverged. This warrants a manual merge!"
|
201
|
+
elsif descriptors.any? { |d| d.state == TheirState::LOCAL_OUTDATED }
|
202
|
+
outcome.outcome = MergeValidationResult::MERGE_UPSTREAM
|
203
|
+
outcome.message = "Some local branches are outdated"
|
204
|
+
end
|
205
|
+
|
206
|
+
return outcome
|
207
|
+
end
|
208
|
+
|
209
|
+
def perform_merges(descriptors)
|
210
|
+
success = true
|
211
|
+
descriptors.each do |descriptor|
|
212
|
+
Console.log_substep("#{descriptor.name} : Merging #{descriptor.their_revision} into #{descriptor.our_revision}...")
|
213
|
+
GitRunner.run_as_system(descriptor.repo.path, "merge #{descriptor.their_revision}")
|
214
|
+
success &= GitRunner.last_command_succeeded
|
215
|
+
end
|
216
|
+
|
217
|
+
if success
|
218
|
+
Console.log_info("All merges performed successfully!")
|
219
|
+
else
|
220
|
+
Console.log_warning("Some merge operations failed. Please review the above.")
|
221
|
+
end
|
222
|
+
|
223
|
+
return success
|
224
|
+
end
|
225
|
+
|
226
|
+
def ask_tracking_files_update(all_merges_succeeded)
|
227
|
+
unless all_merges_succeeded
|
228
|
+
Console.log_warning("Perform a 'multi update' after resolving merge conflicts to ensure lock file contents are valid")
|
229
|
+
return
|
230
|
+
end
|
231
|
+
|
232
|
+
return unless Console.ask("Update main repo tracking files? (important for continuous integration)")
|
233
|
+
|
234
|
+
update_command = UpdateCommand.new(CLAide::ARGV.new(["--commit", "--diff"]))
|
235
|
+
update_command.update_tracking_files_step(RepoSelection::MAIN)
|
236
|
+
end
|
237
|
+
|
238
|
+
def message_for_mode(mode, ref_name)
|
239
|
+
case mode
|
240
|
+
when RevisionSelection::AS_LOCK
|
241
|
+
"merge specific commits as stored in the lock file for main repo revision #{ref_name}"
|
242
|
+
when RevisionSelection::LATEST
|
243
|
+
"merge each branch as stored in the lock file of main repo revision #{ref_name}"
|
244
|
+
when RevisionSelection::EXACT
|
245
|
+
"merge #{ref_name} for each repository, ignoring the contents of the lock file"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|