git-multirepo 1.0.0.beta34 → 1.0.0.beta37
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/.gitignore +38 -38
- data/.multirepo.meta +2 -2
- data/.rspec +2 -2
- data/Gemfile +4 -4
- data/Gemfile.lock +38 -38
- data/LICENSE +22 -22
- data/README.md +143 -143
- data/Rakefile +2 -2
- data/bin/multi +10 -10
- data/docs/bug-repros/91565510-repro.sh +20 -20
- data/docs/git-multirepo-node-dependency-depth-algorithm.pdf +0 -0
- data/docs/graphs/dependencies-on-multiple-levels.graffle +0 -0
- data/docs/graphs/dependencies-on-one-level.graffle +0 -0
- data/git-multirepo.gemspec +29 -29
- data/lib/commands.rb +13 -12
- data/lib/git-multirepo.rb +1 -1
- data/lib/info.rb +4 -4
- data/lib/multirepo/commands/add-command.rb +53 -51
- data/lib/multirepo/commands/branch-command.rb +65 -60
- data/lib/multirepo/commands/checkout-command.rb +119 -140
- data/lib/multirepo/commands/clean-command.rb +31 -31
- data/lib/multirepo/commands/clone-command.rb +70 -70
- data/lib/multirepo/commands/command.rb +71 -71
- data/lib/multirepo/commands/fetch-command.rb +30 -30
- data/lib/multirepo/commands/init-command.rb +119 -119
- data/lib/multirepo/commands/install-command.rb +103 -103
- data/lib/multirepo/commands/merge-command.rb +126 -0
- data/lib/multirepo/commands/open-command.rb +26 -26
- data/lib/multirepo/commands/remove-command.rb +50 -49
- data/lib/multirepo/commands/uninit-command.rb +20 -20
- data/lib/multirepo/commands/update-command.rb +59 -59
- data/lib/multirepo/config.rb +15 -15
- data/lib/multirepo/files/config-entry.rb +34 -34
- data/lib/multirepo/files/config-file.rb +45 -34
- data/lib/multirepo/files/lock-entry.rb +24 -25
- data/lib/multirepo/files/lock-file.rb +39 -28
- data/lib/multirepo/files/meta-file.rb +41 -33
- data/lib/multirepo/files/tracking-file.rb +8 -8
- data/lib/multirepo/files/tracking-files.rb +41 -43
- data/lib/multirepo/git/branch.rb +27 -27
- data/lib/multirepo/git/change.rb +10 -10
- data/lib/multirepo/git/commit.rb +17 -17
- data/lib/multirepo/git/git.rb +39 -39
- data/lib/multirepo/git/remote.rb +16 -16
- data/lib/multirepo/git/repo.rb +77 -77
- data/lib/multirepo/hooks/post-commit-hook.rb +22 -22
- data/lib/multirepo/hooks/pre-commit-hook.rb +29 -29
- data/lib/multirepo/logic/node.rb +41 -0
- data/lib/multirepo/logic/performer.rb +59 -0
- data/lib/multirepo/logic/revision-selector.rb +27 -0
- data/lib/multirepo/multirepo-exception.rb +5 -5
- data/lib/multirepo/utility/console.rb +51 -51
- data/lib/multirepo/utility/runner.rb +34 -34
- data/lib/multirepo/utility/utils.rb +65 -66
- data/resources/.gitconfig +2 -2
- data/resources/post-commit +5 -5
- data/resources/pre-commit +5 -5
- data/spec/integration/init_spec.rb +18 -18
- data/spec/spec_helper.rb +89 -89
- metadata +10 -3
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
data/bin/multi
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "claide"
|
4
|
-
require "commands"
|
5
|
-
|
6
|
-
trap("INT") do
|
7
|
-
puts "\rAbort, abort!!" # \r hides the interrupt control characters
|
8
|
-
exit
|
9
|
-
end
|
10
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "claide"
|
4
|
+
require "commands"
|
5
|
+
|
6
|
+
trap("INT") do
|
7
|
+
puts "\rAbort, abort!!" # \r hides the interrupt control characters
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
11
|
MultiRepo::Command.run(ARGV)
|
@@ -1,21 +1,21 @@
|
|
1
|
-
echo "----> Setup a new test repo"
|
2
|
-
dir_name="PreCommitHookAddTest"
|
3
|
-
rm -rf $dir_name; mkdir $dir_name; cd $dir_name
|
4
|
-
git init; git commit --allow-empty -m "Initial commit"
|
5
|
-
|
6
|
-
echo "----> Add a pre-commit hook that stages a file that doesn't currently exist in the repo"
|
7
|
-
echo "touch auto-added; git add auto-added" > .git/hooks/pre-commit
|
8
|
-
chmod +x .git/hooks/pre-commit
|
9
|
-
|
10
|
-
echo "----> Try committing a new file using the '-o' flag"
|
11
|
-
touch manually-added; git add manually-added
|
12
|
-
git commit -o -m "Commit that ran the pre-commit hook and should contain file 'auto-added'" -- manually-added
|
13
|
-
|
14
|
-
echo "----> Results (expected: working copy clean; actual: auto-added is reported as both DELETED and UNTRACKED. HEAD and working copy are the same, staging area contains ‘incorrect' state)"
|
15
|
-
git status
|
16
|
-
|
17
|
-
echo "----> Stage the file after the fact"
|
18
|
-
git add auto-added
|
19
|
-
|
20
|
-
echo "----> Notice that the working copy is now clean"
|
1
|
+
echo "----> Setup a new test repo"
|
2
|
+
dir_name="PreCommitHookAddTest"
|
3
|
+
rm -rf $dir_name; mkdir $dir_name; cd $dir_name
|
4
|
+
git init; git commit --allow-empty -m "Initial commit"
|
5
|
+
|
6
|
+
echo "----> Add a pre-commit hook that stages a file that doesn't currently exist in the repo"
|
7
|
+
echo "touch auto-added; git add auto-added" > .git/hooks/pre-commit
|
8
|
+
chmod +x .git/hooks/pre-commit
|
9
|
+
|
10
|
+
echo "----> Try committing a new file using the '-o' flag"
|
11
|
+
touch manually-added; git add manually-added
|
12
|
+
git commit -o -m "Commit that ran the pre-commit hook and should contain file 'auto-added'" -- manually-added
|
13
|
+
|
14
|
+
echo "----> Results (expected: working copy clean; actual: auto-added is reported as both DELETED and UNTRACKED. HEAD and working copy are the same, staging area contains ‘incorrect' state)"
|
15
|
+
git status
|
16
|
+
|
17
|
+
echo "----> Stage the file after the fact"
|
18
|
+
git add auto-added
|
19
|
+
|
20
|
+
echo "----> Notice that the working copy is now clean"
|
21
21
|
git status
|
Binary file
|
Binary file
|
Binary file
|
data/git-multirepo.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'info'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = MultiRepo::NAME
|
8
|
-
spec.version = MultiRepo::VERSION
|
9
|
-
spec.authors = ["Michaël Fortin"]
|
10
|
-
spec.email = ["fortinmike@irradiated.net"]
|
11
|
-
spec.summary = %q{Track multiple Git repositories side-by-side}
|
12
|
-
spec.description = MultiRepo::DESCRIPTION
|
13
|
-
spec.homepage = "https://github.com/fortinmike/git-multirepo"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.required_ruby_version = '~> 2.0'
|
17
|
-
spec.files = `git ls-files -z`.split("\x0")
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.1.0"
|
25
|
-
|
26
|
-
spec.add_runtime_dependency "claide", "~> 0.8", ">= 0.8.0"
|
27
|
-
spec.add_runtime_dependency "colored", "~> 1.2"
|
28
|
-
spec.add_runtime_dependency "os", "~> 0.9.6"
|
29
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'info'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = MultiRepo::NAME
|
8
|
+
spec.version = MultiRepo::VERSION
|
9
|
+
spec.authors = ["Michaël Fortin"]
|
10
|
+
spec.email = ["fortinmike@irradiated.net"]
|
11
|
+
spec.summary = %q{Track multiple Git repositories side-by-side}
|
12
|
+
spec.description = MultiRepo::DESCRIPTION
|
13
|
+
spec.homepage = "https://github.com/fortinmike/git-multirepo"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.required_ruby_version = '~> 2.0'
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.1.0"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "claide", "~> 0.8", ">= 0.8.0"
|
27
|
+
spec.add_runtime_dependency "colored", "~> 1.2"
|
28
|
+
spec.add_runtime_dependency "os", "~> 0.9.6"
|
29
|
+
end
|
data/lib/commands.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
require_relative "multirepo/commands/command"
|
2
|
-
require_relative "multirepo/commands/add-command"
|
3
|
-
require_relative "multirepo/commands/branch-command"
|
4
|
-
require_relative "multirepo/commands/checkout-command"
|
5
|
-
require_relative "multirepo/commands/clean-command"
|
6
|
-
require_relative "multirepo/commands/clone-command"
|
7
|
-
require_relative "multirepo/commands/fetch-command"
|
8
|
-
require_relative "multirepo/commands/init-command"
|
9
|
-
require_relative "multirepo/commands/install-command"
|
10
|
-
require_relative "multirepo/commands/
|
11
|
-
require_relative "multirepo/commands/
|
12
|
-
require_relative "multirepo/commands/
|
1
|
+
require_relative "multirepo/commands/command"
|
2
|
+
require_relative "multirepo/commands/add-command"
|
3
|
+
require_relative "multirepo/commands/branch-command"
|
4
|
+
require_relative "multirepo/commands/checkout-command"
|
5
|
+
require_relative "multirepo/commands/clean-command"
|
6
|
+
require_relative "multirepo/commands/clone-command"
|
7
|
+
require_relative "multirepo/commands/fetch-command"
|
8
|
+
require_relative "multirepo/commands/init-command"
|
9
|
+
require_relative "multirepo/commands/install-command"
|
10
|
+
require_relative "multirepo/commands/merge-command"
|
11
|
+
require_relative "multirepo/commands/open-command"
|
12
|
+
require_relative "multirepo/commands/remove-command"
|
13
|
+
require_relative "multirepo/commands/uninit-command"
|
13
14
|
require_relative "multirepo/commands/update-command"
|
data/lib/git-multirepo.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "multirepo/hooks/pre-commit-hook.rb"
|
1
|
+
require "multirepo/hooks/pre-commit-hook.rb"
|
2
2
|
require "multirepo/hooks/post-commit-hook.rb"
|
data/lib/info.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module MultiRepo
|
2
|
-
NAME = "git-multirepo"
|
3
|
-
VERSION = "1.0.0.
|
4
|
-
DESCRIPTION = "Track multiple Git repositories side-by-side."
|
1
|
+
module MultiRepo
|
2
|
+
NAME = "git-multirepo"
|
3
|
+
VERSION = "1.0.0.beta37"
|
4
|
+
DESCRIPTION = "Track multiple Git repositories side-by-side."
|
5
5
|
end
|
@@ -1,52 +1,54 @@
|
|
1
|
-
require "multirepo/utility/console"
|
2
|
-
require "multirepo/files/config-file"
|
3
|
-
|
4
|
-
module MultiRepo
|
5
|
-
class AddCommand < Command
|
6
|
-
self.command = "add"
|
7
|
-
self.summary = "Track an additional dependency with multirepo."
|
8
|
-
|
9
|
-
def self.options
|
10
|
-
[['<path>', 'The relative path to the new dependency (e.g. ../MyNewDependency)']].concat(super)
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(argv)
|
14
|
-
@path = argv.shift_argument
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
18
|
-
def validate!
|
19
|
-
super
|
20
|
-
help! "You must specify a repository to add as a dependency" unless @path
|
21
|
-
end
|
22
|
-
|
23
|
-
def run
|
24
|
-
super
|
25
|
-
ensure_in_work_tree
|
26
|
-
ensure_multirepo_enabled
|
27
|
-
ensure_repo_valid
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
raise MultiRepoException, "
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
1
|
+
require "multirepo/utility/console"
|
2
|
+
require "multirepo/files/config-file"
|
3
|
+
|
4
|
+
module MultiRepo
|
5
|
+
class AddCommand < Command
|
6
|
+
self.command = "add"
|
7
|
+
self.summary = "Track an additional dependency with multirepo."
|
8
|
+
|
9
|
+
def self.options
|
10
|
+
[['<path>', 'The relative path to the new dependency (e.g. ../MyNewDependency)']].concat(super)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(argv)
|
14
|
+
@path = argv.shift_argument
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate!
|
19
|
+
super
|
20
|
+
help! "You must specify a repository to add as a dependency" unless @path
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
super
|
25
|
+
ensure_in_work_tree
|
26
|
+
ensure_multirepo_enabled
|
27
|
+
ensure_repo_valid
|
28
|
+
|
29
|
+
config_file = ConfigFile.new(".")
|
30
|
+
entry = ConfigEntry.new(Repo.new(@path))
|
31
|
+
|
32
|
+
if config_file.entry_exists?(entry)
|
33
|
+
Console.log_info("There is already an entry for '#{@path}' in the .multirepo file")
|
34
|
+
else
|
35
|
+
config_file.add_entry(entry)
|
36
|
+
Console.log_step("Added '#{@path}' to the .multirepo file")
|
37
|
+
end
|
38
|
+
rescue MultiRepoException => e
|
39
|
+
Console.log_error(e.message)
|
40
|
+
end
|
41
|
+
|
42
|
+
def ensure_repo_valid
|
43
|
+
raise MultiRepoException, "The provided path is not a direct sibling of the main repository" unless validate_is_sibling_repo(@path)
|
44
|
+
raise MultiRepoException, "There is no folder at path '#{@path}'" unless Dir.exists?(@path)
|
45
|
+
raise MultiRepoException, "'#{@path}' is not a repository" unless Repo.new(@path).exists?
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_is_sibling_repo(path)
|
49
|
+
parent_dir = File.expand_path("..")
|
50
|
+
path = File.expand_path("..", path)
|
51
|
+
return parent_dir == path
|
52
|
+
end
|
53
|
+
end
|
52
54
|
end
|
@@ -1,61 +1,66 @@
|
|
1
|
-
require "multirepo/utility/console"
|
2
|
-
require "multirepo/files/config-file"
|
3
|
-
require "multirepo/files/tracking-files"
|
4
|
-
|
5
|
-
module MultiRepo
|
6
|
-
class BranchCommand < Command
|
7
|
-
self.command = "branch"
|
8
|
-
self.summary = "Create and/or checkout a new branch for all repos."
|
9
|
-
|
10
|
-
def self.options
|
11
|
-
[
|
12
|
-
['<branch name>', 'The name of the branch to create and checkout.'],
|
13
|
-
['[--force]', 'Force creating the branch even if the repos contain uncommmitted changes.'],
|
14
|
-
['[--no-track]', 'Do not configure as a remote-tracking branch on creation.']
|
15
|
-
].concat(super)
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(argv)
|
19
|
-
@branch_name = argv.shift_argument
|
20
|
-
@force = argv.flag?("force")
|
21
|
-
@remote_tracking = argv.flag?("track", true)
|
22
|
-
super
|
23
|
-
end
|
24
|
-
|
25
|
-
def validate!
|
26
|
-
super
|
27
|
-
help! "You must specify a branch name" unless @branch_name
|
28
|
-
end
|
29
|
-
|
30
|
-
def run
|
31
|
-
super
|
32
|
-
ensure_in_work_tree
|
33
|
-
ensure_multirepo_enabled
|
34
|
-
|
35
|
-
Console.log_step("Branching...")
|
36
|
-
|
37
|
-
main_repo = Repo.new(".")
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
1
|
+
require "multirepo/utility/console"
|
2
|
+
require "multirepo/files/config-file"
|
3
|
+
require "multirepo/files/tracking-files"
|
4
|
+
|
5
|
+
module MultiRepo
|
6
|
+
class BranchCommand < Command
|
7
|
+
self.command = "branch"
|
8
|
+
self.summary = "Create and/or checkout a new branch for all repos."
|
9
|
+
|
10
|
+
def self.options
|
11
|
+
[
|
12
|
+
['<branch name>', 'The name of the branch to create and checkout.'],
|
13
|
+
['[--force]', 'Force creating the branch even if the repos contain uncommmitted changes.'],
|
14
|
+
['[--no-track]', 'Do not configure as a remote-tracking branch on creation.']
|
15
|
+
].concat(super)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(argv)
|
19
|
+
@branch_name = argv.shift_argument
|
20
|
+
@force = argv.flag?("force")
|
21
|
+
@remote_tracking = argv.flag?("track", true)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate!
|
26
|
+
super
|
27
|
+
help! "You must specify a branch name" unless @branch_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
super
|
32
|
+
ensure_in_work_tree
|
33
|
+
ensure_multirepo_enabled
|
34
|
+
|
35
|
+
Console.log_step("Branching...")
|
36
|
+
|
37
|
+
main_repo = Repo.new(".")
|
38
|
+
config_file = ConfigFile.new(".")
|
39
|
+
repos = config_file.load_entries.map{ |entry| entry.repo }.push(main_repo)
|
40
|
+
|
41
|
+
if !Utils.ensure_working_copies_clean(repos) && !@force
|
42
|
+
raise MultiRepoException, "Can't branch because not all repos are clean"
|
43
|
+
end
|
44
|
+
|
45
|
+
repos.each do |repo|
|
46
|
+
if @remote_tracking
|
47
|
+
Console.log_substep("Branching, checking out and pushing '#{repo.path}' #{@branch_name} ...")
|
48
|
+
else
|
49
|
+
Console.log_substep("Branching and checking out '#{repo.path}' #{@branch_name} (not pushed) ...")
|
50
|
+
end
|
51
|
+
|
52
|
+
branch = repo.branch(@branch_name)
|
53
|
+
branch.create(@remote_tracking) unless branch.exists?
|
54
|
+
branch.checkout
|
55
|
+
end
|
56
|
+
|
57
|
+
Console.log_substep("Updating and committing tracking files")
|
58
|
+
TrackingFiles.update
|
59
|
+
TrackingFiles.commit("[multirepo] Post-branch tracking files update")
|
60
|
+
|
61
|
+
Console.log_step("Done!")
|
62
|
+
rescue MultiRepoException => e
|
63
|
+
Console.log_error(e.message)
|
64
|
+
end
|
65
|
+
end
|
61
66
|
end
|
@@ -1,141 +1,120 @@
|
|
1
|
-
require "multirepo/utility/console"
|
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
|
-
super
|
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
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
Console.
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
# (in case the checked-out revision had an additional dependency)
|
121
|
-
unless config_entry.repo.exists?
|
122
|
-
Console.log_substep("Cloning missing dependency '#{config_entry.path}' from #{config_entry.url}")
|
123
|
-
config_entry.repo.clone(config_entry.url)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Find out the proper revision to checkout based on the checkout mode
|
127
|
-
revision = case mode
|
128
|
-
when CheckoutMode::AS_LOCK; lock_entry.head
|
129
|
-
when CheckoutMode::LATEST; lock_entry.branch
|
130
|
-
when CheckoutMode::EXACT; ref
|
131
|
-
end
|
132
|
-
|
133
|
-
# Checkout!
|
134
|
-
if config_entry.repo.checkout(revision)
|
135
|
-
Console.log_substep("Checked out #{lock_entry.name} #{revision}")
|
136
|
-
else
|
137
|
-
raise MultiRepoException, "Couldn't check out the appropriate version of dependency #{lock_entry.name}"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
1
|
+
require "multirepo/utility/console"
|
2
|
+
require "multirepo/logic/revision-selector"
|
3
|
+
require "multirepo/logic/performer"
|
4
|
+
|
5
|
+
module MultiRepo
|
6
|
+
class CheckoutCommand < Command
|
7
|
+
self.command = "checkout"
|
8
|
+
self.summary = "Checks out the specified commit or branch of the main repo and checks out matching versions of all dependencies."
|
9
|
+
|
10
|
+
def self.options
|
11
|
+
[
|
12
|
+
['<ref>', 'The main repo tag, branch or commit id to checkout.'],
|
13
|
+
['[--latest]', 'Checkout the HEAD of each dependency branch (as recorded in the lock file) instead of the exact required commits.'],
|
14
|
+
['[--exact]', 'Checkout the exact specified ref for each repo, regardless of what\'s stored in the lock file.']
|
15
|
+
].concat(super)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(argv)
|
19
|
+
@ref = argv.shift_argument
|
20
|
+
@checkout_latest = argv.flag?("latest")
|
21
|
+
@checkout_exact = argv.flag?("exact")
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate!
|
26
|
+
super
|
27
|
+
help! "You must specify a branch or commit id to checkout" unless @ref
|
28
|
+
help! "You can't provide more than one operation modifier (--latest, --exact, etc.)" if @checkout_latest && @checkout_exact
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
super
|
33
|
+
ensure_in_work_tree
|
34
|
+
|
35
|
+
Console.log_step("Checking out #{@ref} and its dependencies...")
|
36
|
+
|
37
|
+
# Find out the checkout mode based on command-line options
|
38
|
+
mode = RevisionSelector.mode_for_args(@checkout_latest, @checkout_exact)
|
39
|
+
|
40
|
+
main_repo = Repo.new(".")
|
41
|
+
|
42
|
+
unless proceed_if_merge_commit?(main_repo, @ref, mode)
|
43
|
+
raise MultiRepoException, "Aborting checkout"
|
44
|
+
end
|
45
|
+
|
46
|
+
checkout_core(main_repo, mode)
|
47
|
+
|
48
|
+
Console.log_step("Done!")
|
49
|
+
rescue MultiRepoException => e
|
50
|
+
Console.log_error(e.message)
|
51
|
+
end
|
52
|
+
|
53
|
+
def checkout_core(main_repo, mode)
|
54
|
+
initial_revision = main_repo.current_branch || main_repo.head_hash
|
55
|
+
begin
|
56
|
+
# Checkout first because the current ref might not be multirepo-enabled
|
57
|
+
checkout_main_repo_step(main_repo)
|
58
|
+
# Only then can we check for dependencies and make sure they are clean
|
59
|
+
ensure_dependencies_clean_step(main_repo)
|
60
|
+
rescue MultiRepoException => e
|
61
|
+
Console.log_error("Reverting main repo checkout")
|
62
|
+
main_repo.checkout(initial_revision)
|
63
|
+
raise e
|
64
|
+
end
|
65
|
+
dependencies_checkout_step(mode, @ref)
|
66
|
+
end
|
67
|
+
|
68
|
+
def checkout_main_repo_step(main_repo)
|
69
|
+
Performer.perform_main_repo_checkout(main_repo, @ref)
|
70
|
+
end
|
71
|
+
|
72
|
+
def ensure_dependencies_clean_step(main_repo)
|
73
|
+
unless Utils.ensure_dependencies_clean(ConfigFile.new(".").load_entries)
|
74
|
+
raise MultiRepoException, "Dependencies are not clean!"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def dependencies_checkout_step(mode, ref = nil)
|
79
|
+
Performer.perform_on_dependencies do |config_entry, lock_entry|
|
80
|
+
# Find out the required dependency revision based on the checkout mode
|
81
|
+
revision = RevisionSelector.revision_for_mode(mode, ref, lock_entry)
|
82
|
+
perform_dependency_checkout(config_entry, revision)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def proceed_if_merge_commit?(main_repo, ref, mode)
|
87
|
+
return true unless main_repo.commit(ref).is_merge?
|
88
|
+
|
89
|
+
case mode
|
90
|
+
when RevisionSelectionMode::AS_LOCK
|
91
|
+
Console.log_error("The specified ref is a merge commit and an \"as-lock\" checkout was requested.")
|
92
|
+
Console.log_error("The resulting checkout would most probably not result in a valid project state.")
|
93
|
+
return false
|
94
|
+
when RevisionSelectionMode::LATEST
|
95
|
+
Console.log_warning("The specified ref is a merge commit and a \"latest\" checkout was requested.")
|
96
|
+
Console.log_warning("The work branches recorded in the branch from which the merge was performed will be checked out.")
|
97
|
+
end
|
98
|
+
|
99
|
+
return true
|
100
|
+
end
|
101
|
+
|
102
|
+
def perform_dependency_checkout(config_entry, revision)
|
103
|
+
dependency_name = config_entry.repo.basename
|
104
|
+
|
105
|
+
# Make sure the repo exists on disk, and clone it if it doesn't
|
106
|
+
# (in case the checked-out revision had an additional dependency)
|
107
|
+
unless config_entry.repo.exists?
|
108
|
+
Console.log_substep("Cloning missing dependency '#{config_entry.path}' from #{config_entry.url}")
|
109
|
+
config_entry.repo.clone(config_entry.url)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Checkout!
|
113
|
+
if config_entry.repo.checkout(revision)
|
114
|
+
Console.log_substep("Checked out #{dependency_name} #{revision}")
|
115
|
+
else
|
116
|
+
raise MultiRepoException, "Couldn't check out the appropriate version of dependency #{dependency_name}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
141
120
|
end
|