git-multirepo 1.0.0.beta27 → 1.0.0.beta29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +38 -38
  3. data/.rspec +2 -2
  4. data/Gemfile +4 -4
  5. data/Gemfile.lock +38 -38
  6. data/LICENSE +22 -22
  7. data/README.md +141 -141
  8. data/Rakefile +2 -2
  9. data/bin/multi +10 -10
  10. data/git-multirepo.gemspec +29 -29
  11. data/lib/commands.rb +11 -11
  12. data/lib/git-multirepo.rb +1 -3
  13. data/lib/info.rb +4 -4
  14. data/lib/multirepo/commands/add-command.rb +50 -51
  15. data/lib/multirepo/commands/branch-command.rb +59 -59
  16. data/lib/multirepo/commands/checkout-command.rb +139 -119
  17. data/lib/multirepo/commands/clone-command.rb +69 -69
  18. data/lib/multirepo/commands/command.rb +62 -62
  19. data/lib/multirepo/commands/fetch-command.rb +23 -23
  20. data/lib/multirepo/commands/init-command.rb +94 -51
  21. data/lib/multirepo/commands/install-command.rb +104 -87
  22. data/lib/multirepo/commands/open-command.rb +25 -25
  23. data/lib/multirepo/commands/remove-command.rb +48 -48
  24. data/lib/multirepo/commands/uninit-command.rb +19 -19
  25. data/lib/multirepo/commands/update-command.rb +53 -47
  26. data/lib/multirepo/config.rb +15 -15
  27. data/lib/multirepo/files/config-entry.rb +34 -34
  28. data/lib/multirepo/files/config-file.rb +33 -37
  29. data/lib/multirepo/files/lock-entry.rb +25 -25
  30. data/lib/multirepo/files/lock-file.rb +44 -39
  31. data/lib/multirepo/git/branch.rb +27 -27
  32. data/lib/multirepo/git/change.rb +10 -10
  33. data/lib/multirepo/git/commit.rb +18 -0
  34. data/lib/multirepo/git/git.rb +42 -42
  35. data/lib/multirepo/git/remote.rb +15 -15
  36. data/lib/multirepo/git/repo.rb +71 -66
  37. data/lib/multirepo/hooks/pre-commit-hook.rb +29 -25
  38. data/lib/multirepo/multirepo-exception.rb +5 -5
  39. data/lib/multirepo/utility/console.rb +51 -51
  40. data/lib/multirepo/utility/runner.rb +32 -32
  41. data/lib/multirepo/utility/utils.rb +66 -54
  42. data/resources/.gitconfig +3 -0
  43. data/resources/pre-commit +5 -5
  44. data/spec/integration/init_spec.rb +18 -22
  45. data/spec/spec_helper.rb +89 -89
  46. metadata +5 -7
  47. data/lib/multirepo/hooks/post-merge-hook.rb +0 -20
  48. data/lib/multirepo/hooks/prepare-commit-msg-hook.rb +0 -28
  49. data/resources/post-merge +0 -6
  50. data/resources/prepare-commit-msg +0 -6
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,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,12 +1,12 @@
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/clone-command"
6
- require_relative "multirepo/commands/fetch-command"
7
- require_relative "multirepo/commands/init-command"
8
- require_relative "multirepo/commands/install-command"
9
- require_relative "multirepo/commands/open-command"
10
- require_relative "multirepo/commands/remove-command"
11
- require_relative "multirepo/commands/uninit-command"
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/clone-command"
6
+ require_relative "multirepo/commands/fetch-command"
7
+ require_relative "multirepo/commands/init-command"
8
+ require_relative "multirepo/commands/install-command"
9
+ require_relative "multirepo/commands/open-command"
10
+ require_relative "multirepo/commands/remove-command"
11
+ require_relative "multirepo/commands/uninit-command"
12
12
  require_relative "multirepo/commands/update-command"
data/lib/git-multirepo.rb CHANGED
@@ -1,3 +1 @@
1
- require "multirepo/hooks/pre-commit-hook.rb"
2
- require "multirepo/hooks/prepare-commit-msg-hook.rb"
3
- require "multirepo/hooks/post-merge-hook.rb"
1
+ require "multirepo/hooks/pre-commit-hook.rb"
data/lib/info.rb CHANGED
@@ -1,5 +1,5 @@
1
- module MultiRepo
2
- NAME = "git-multirepo"
3
- VERSION = "1.0.0.beta27"
4
- DESCRIPTION = "Track multiple Git repositories side-by-side."
1
+ module MultiRepo
2
+ NAME = "git-multirepo"
3
+ VERSION = "1.0.0.beta29"
4
+ DESCRIPTION = "Track multiple Git repositories side-by-side."
5
5
  end
@@ -1,52 +1,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
- validate_in_work_tree
25
- ensure_multirepo_enabled
26
- ensure_repo_valid
27
-
28
- entry = ConfigEntry.new(Repo.new(@path))
29
- if ConfigFile.entry_exists?(entry)
30
- Console.log_info("There is already an entry for '#{@path}' in the .multirepo file")
31
- else
32
- ConfigFile.add_entry(entry)
33
- ConfigFile.stage
34
- Console.log_step("Added '#{@path}' to the .multirepo file")
35
- end
36
- rescue MultiRepoException => e
37
- Console.log_error(e.message)
38
- end
39
-
40
- def ensure_repo_valid
41
- raise MultiRepoException, "The provided path is not a direct sibling of the main repository" unless validate_is_sibling_repo(@path)
42
- raise MultiRepoException, "There is no folder at path '#{@path}'" unless Dir.exists?(@path)
43
- raise MultiRepoException, "'#{@path}' is not a repository" unless Repo.new(@path).exists?
44
- end
45
-
46
- def validate_is_sibling_repo(path)
47
- parent_dir = File.expand_path("..")
48
- path = File.expand_path("..", path)
49
- return parent_dir == path
50
- end
51
- end
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
+ validate_in_work_tree
25
+ ensure_multirepo_enabled
26
+ ensure_repo_valid
27
+
28
+ entry = ConfigEntry.new(Repo.new(@path))
29
+ if ConfigFile.entry_exists?(entry)
30
+ Console.log_info("There is already an entry for '#{@path}' in the .multirepo file")
31
+ else
32
+ ConfigFile.add_entry(entry)
33
+ Console.log_step("Added '#{@path}' to the .multirepo file")
34
+ end
35
+ rescue MultiRepoException => e
36
+ Console.log_error(e.message)
37
+ end
38
+
39
+ def ensure_repo_valid
40
+ raise MultiRepoException, "The provided path is not a direct sibling of the main repository" unless validate_is_sibling_repo(@path)
41
+ raise MultiRepoException, "There is no folder at path '#{@path}'" unless Dir.exists?(@path)
42
+ raise MultiRepoException, "'#{@path}' is not a repository" unless Repo.new(@path).exists?
43
+ end
44
+
45
+ def validate_is_sibling_repo(path)
46
+ parent_dir = File.expand_path("..")
47
+ path = File.expand_path("..", path)
48
+ return parent_dir == path
49
+ end
50
+ end
52
51
  end
@@ -1,60 +1,60 @@
1
- require "multirepo/utility/console"
2
- require "multirepo/files/config-file"
3
- require "multirepo/files/lock-file"
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
- validate_in_work_tree
32
- ensure_multirepo_enabled
33
-
34
- Console.log_step("Branching...")
35
-
36
- main_repo = main_repo = Repo.new(".")
37
- repos = ConfigFile.load.map{ |entry| entry.repo }.push(main_repo)
38
-
39
- if !Utils.ensure_working_copies_clean(repos) && !@force
40
- raise MultiRepoException, "Can't branch because not all repos are clean"
41
- end
42
-
43
- repos.each do |repo|
44
- Console.log_substep("Branching and checking out #{repo.path} #{@branch_name} ...")
45
-
46
- branch = repo.branch(@branch_name)
47
- branch.create(@remote_tracking) unless branch.exists?
48
- branch.checkout
49
- end
50
-
51
- Console.log_substep("Updating and committing lock file")
52
- LockFile.update
53
- LockFile.commit("[multirepo] Post-branch lock file update")
54
-
55
- Console.log_step("Done!")
56
- rescue MultiRepoException => e
57
- Console.log_error(e.message)
58
- end
59
- end
1
+ require "multirepo/utility/console"
2
+ require "multirepo/files/config-file"
3
+ require "multirepo/files/lock-file"
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
+ validate_in_work_tree
32
+ ensure_multirepo_enabled
33
+
34
+ Console.log_step("Branching...")
35
+
36
+ main_repo = main_repo = Repo.new(".")
37
+ repos = ConfigFile.load.map{ |entry| entry.repo }.push(main_repo)
38
+
39
+ if !Utils.ensure_working_copies_clean(repos) && !@force
40
+ raise MultiRepoException, "Can't branch because not all repos are clean"
41
+ end
42
+
43
+ repos.each do |repo|
44
+ Console.log_substep("Branching and checking out #{repo.path} #{@branch_name} ...")
45
+
46
+ branch = repo.branch(@branch_name)
47
+ branch.create(@remote_tracking) unless branch.exists?
48
+ branch.checkout
49
+ end
50
+
51
+ Console.log_substep("Updating and committing lock file")
52
+ LockFile.update
53
+ LockFile.commit("[multirepo] Post-branch lock file update")
54
+
55
+ Console.log_step("Done!")
56
+ rescue MultiRepoException => e
57
+ Console.log_error(e.message)
58
+ end
59
+ end
60
60
  end
@@ -1,120 +1,140 @@
1
- require "multirepo/utility/console"
2
-
3
- module MultiRepo
4
- class CheckoutCommand < Command
5
- self.command = "checkout"
6
- self.summary = "Checks out the specified commit or branch of the main repo and checks out matching versions of all dependencies."
7
-
8
- class CheckoutMode
9
- AS_LOCK = 0
10
- LATEST = 1
11
- EXACT = 2
12
- end
13
-
14
- def self.options
15
- [
16
- ['<ref>', 'The main repo tag, branch or commit id to checkout.'],
17
- ['[--latest]', 'Checkout the HEAD of each dependency branch (as recorded in the lock file) instead of the exact required commits.'],
18
- ['[--exact]', 'Checkout the exact specified ref for each repo, regardless of what\'s stored in the lock file.']
19
- ].concat(super)
20
- end
21
-
22
- def initialize(argv)
23
- @ref = argv.shift_argument
24
- @checkout_latest = argv.flag?("latest")
25
- @checkout_exact = argv.flag?("exact")
26
- super
27
- end
28
-
29
- def validate!
30
- super
31
- help! "You must specify a branch or commit id to checkout" unless @ref
32
- help! "You can't provide more than one operation modifier (--latest, --exact, etc.)" if @checkout_latest && @checkout_exact
33
- end
34
-
35
- def run
36
- validate_in_work_tree
37
- ensure_multirepo_enabled
38
-
39
- Console.log_step("Checking out #{@ref} and its dependencies...")
40
-
41
- # Find out the checkout mode based on command-line options
42
- mode = if @checkout_latest then
43
- CheckoutMode::LATEST
44
- elsif @checkout_exact then
45
- CheckoutMode::EXACT
46
- else
47
- CheckoutMode::AS_LOCK
48
- end
49
-
50
- main_repo = Repo.new(".")
51
- initial_revision = main_repo.current_branch || main_repo.head_hash
52
-
53
- main_repo_checkout_step(main_repo, initial_revision, @ref)
54
- ensure_dependencies_clean_step(main_repo, initial_revision)
55
- dependencies_checkout_step(mode, @ref)
56
-
57
- Console.log_step("Done!")
58
- rescue MultiRepoException => e
59
- Console.log_error(e.message)
60
- end
61
-
62
- def main_repo_checkout_step(main_repo, initial_revision, ref)
63
- # Make sure the main repo is clean before attempting a checkout
64
- unless main_repo.is_clean?
65
- raise MultiRepoException, "Can't checkout #{ref} because the main repo contains uncommitted changes"
66
- end
67
-
68
- # Checkout the specified ref
69
- unless main_repo.checkout(ref)
70
- raise MultiRepoException, "Couldn't perform checkout of main repo #{ref}!"
71
- end
72
-
73
- Console.log_substep("Checked out main repo #{ref}")
74
-
75
- # After checkout, make sure we're working with a multirepo-enabled ref
76
- unless Utils.is_multirepo_tracked(".")
77
- main_repo.checkout(initial_revision)
78
- raise MultiRepoException, "This revision is not tracked by multirepo. Checkout reverted."
79
- end
80
- end
81
-
82
- def ensure_dependencies_clean_step(main_repo, initial_revision)
83
- unless Utils.ensure_dependencies_clean(ConfigFile.load)
84
- main_repo.checkout(initial_revision)
85
- raise MultiRepoException, "Checkout reverted."
86
- end
87
- end
88
-
89
- def dependencies_checkout_step(mode, ref = nil)
90
- config_entries = ConfigFile.load # Post-main-repo checkout config entries might be different than pre-checkout
91
- LockFile.load.each { |lock_entry| perform_dependency_checkout(config_entries, lock_entry, ref, mode) }
92
- end
93
-
94
- def perform_dependency_checkout(config_entries, lock_entry, ref, mode)
95
- # Find the config entry that matches the given lock entry
96
- config_entry = config_entries.select{ |config_entry| config_entry.id == lock_entry.id }.first
97
-
98
- # Make sure the repo exists on disk, and clone it if it doesn't
99
- # (in case the checked-out revision had an additional dependency)
100
- unless config_entry.repo.exists?
101
- Console.log_substep("Cloning missing dependency '#{config_entry.path}' from #{config_entry.url}")
102
- config_entry.repo.clone(config_entry.url)
103
- end
104
-
105
- # Find out the proper revision to checkout based on the checkout mode
106
- revision = case mode
107
- when CheckoutMode::AS_LOCK; lock_entry.head
108
- when CheckoutMode::LATEST; lock_entry.branch
109
- when CheckoutMode::EXACT; ref
110
- end
111
-
112
- # Checkout!
113
- if config_entry.repo.checkout(revision)
114
- Console.log_substep("Checked out #{lock_entry.name} #{revision}")
115
- else
116
- raise MultiRepoException, "Couldn't check out the appropriate version of dependency #{lock_entry.name}"
117
- end
118
- end
119
- end
1
+ require "multirepo/utility/console"
2
+
3
+ module MultiRepo
4
+ class CheckoutCommand < Command
5
+ self.command = "checkout"
6
+ self.summary = "Checks out the specified commit or branch of the main repo and checks out matching versions of all dependencies."
7
+
8
+ class CheckoutMode
9
+ AS_LOCK = 0
10
+ LATEST = 1
11
+ EXACT = 2
12
+ end
13
+
14
+ def self.options
15
+ [
16
+ ['<ref>', 'The main repo tag, branch or commit id to checkout.'],
17
+ ['[--latest]', 'Checkout the HEAD of each dependency branch (as recorded in the lock file) instead of the exact required commits.'],
18
+ ['[--exact]', 'Checkout the exact specified ref for each repo, regardless of what\'s stored in the lock file.']
19
+ ].concat(super)
20
+ end
21
+
22
+ def initialize(argv)
23
+ @ref = argv.shift_argument
24
+ @checkout_latest = argv.flag?("latest")
25
+ @checkout_exact = argv.flag?("exact")
26
+ super
27
+ end
28
+
29
+ def validate!
30
+ super
31
+ help! "You must specify a branch or commit id to checkout" unless @ref
32
+ help! "You can't provide more than one operation modifier (--latest, --exact, etc.)" if @checkout_latest && @checkout_exact
33
+ end
34
+
35
+ def run
36
+ validate_in_work_tree
37
+ ensure_multirepo_enabled
38
+
39
+ Console.log_step("Checking out #{@ref} and its dependencies...")
40
+
41
+ # Find out the checkout mode based on command-line options
42
+ mode = if @checkout_latest then
43
+ CheckoutMode::LATEST
44
+ elsif @checkout_exact then
45
+ CheckoutMode::EXACT
46
+ else
47
+ CheckoutMode::AS_LOCK
48
+ end
49
+
50
+ main_repo = Repo.new(".")
51
+ initial_revision = main_repo.current_branch || main_repo.head_hash
52
+
53
+ unless proceed_if_merge_commit?(main_repo, @ref, mode)
54
+ raise MultiRepoException, "Aborting checkout"
55
+ end
56
+
57
+ main_repo_checkout_step(main_repo, initial_revision, @ref)
58
+ ensure_dependencies_clean_step(main_repo, initial_revision)
59
+ dependencies_checkout_step(mode, @ref)
60
+
61
+ Console.log_step("Done!")
62
+ rescue MultiRepoException => e
63
+ Console.log_error(e.message)
64
+ end
65
+
66
+ def main_repo_checkout_step(main_repo, initial_revision, ref)
67
+ # Make sure the main repo is clean before attempting a checkout
68
+ unless main_repo.is_clean?
69
+ raise MultiRepoException, "Can't checkout #{ref} because the main repo contains uncommitted changes"
70
+ end
71
+
72
+ # Checkout the specified ref
73
+ unless main_repo.checkout(ref)
74
+ raise MultiRepoException, "Couldn't perform checkout of main repo #{ref}!"
75
+ end
76
+
77
+ Console.log_substep("Checked out main repo #{ref}")
78
+
79
+ # After checkout, make sure we're working with a multirepo-enabled ref
80
+ unless Utils.is_multirepo_tracked(".")
81
+ main_repo.checkout(initial_revision)
82
+ raise MultiRepoException, "This revision is not tracked by multirepo. Checkout reverted."
83
+ end
84
+ end
85
+
86
+ def ensure_dependencies_clean_step(main_repo, initial_revision)
87
+ unless Utils.ensure_dependencies_clean(ConfigFile.load)
88
+ main_repo.checkout(initial_revision)
89
+ raise MultiRepoException, "Checkout reverted."
90
+ end
91
+ end
92
+
93
+ def dependencies_checkout_step(mode, ref = nil)
94
+ config_entries = ConfigFile.load # Post-main-repo checkout config entries might be different than pre-checkout
95
+ LockFile.load.each { |lock_entry| perform_dependency_checkout(config_entries, lock_entry, ref, mode) }
96
+ end
97
+
98
+ def proceed_if_merge_commit?(main_repo, ref, mode)
99
+ return true unless main_repo.commit(ref).is_merge?
100
+
101
+ case mode
102
+ when CheckoutMode::AS_LOCK
103
+ Console.log_error("The specified ref is a merge commit and an \"as-lock\" checkout was requested.")
104
+ Console.log_error("The resulting checkout would most probably not result in a valid project state.")
105
+ return false
106
+ when CheckoutMode::LATEST
107
+ Console.log_warning("The specified ref is a merge commit and a \"latest\" checkout was requested.")
108
+ Console.log_warning("The work branches recorded in the branch from which the merge was performed will be checked out.")
109
+ end
110
+
111
+ return true
112
+ end
113
+
114
+ def perform_dependency_checkout(config_entries, lock_entry, ref, mode)
115
+ # Find the config entry that matches the given lock entry
116
+ config_entry = config_entries.select{ |config_entry| config_entry.id == lock_entry.id }.first
117
+
118
+ # Make sure the repo exists on disk, and clone it if it doesn't
119
+ # (in case the checked-out revision had an additional dependency)
120
+ unless config_entry.repo.exists?
121
+ Console.log_substep("Cloning missing dependency '#{config_entry.path}' from #{config_entry.url}")
122
+ config_entry.repo.clone(config_entry.url)
123
+ end
124
+
125
+ # Find out the proper revision to checkout based on the checkout mode
126
+ revision = case mode
127
+ when CheckoutMode::AS_LOCK; lock_entry.head
128
+ when CheckoutMode::LATEST; lock_entry.branch
129
+ when CheckoutMode::EXACT; ref
130
+ end
131
+
132
+ # Checkout!
133
+ if config_entry.repo.checkout(revision)
134
+ Console.log_substep("Checked out #{lock_entry.name} #{revision}")
135
+ else
136
+ raise MultiRepoException, "Couldn't check out the appropriate version of dependency #{lock_entry.name}"
137
+ end
138
+ end
139
+ end
120
140
  end