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