git-multirepo 1.0.0.beta45 → 1.0.0.beta46
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.
- checksums.yaml +4 -4
- data/.gitattributes +2 -2
- data/.gitbugtraq +3 -3
- data/.gitignore +38 -38
- data/.multirepo +21 -21
- data/.multirepo.lock +26 -26
- data/.multirepo.meta +2 -2
- data/.rspec +2 -2
- data/Gemfile +4 -4
- data/Gemfile.lock +42 -42
- data/LICENSE +22 -22
- data/README.md +154 -144
- data/Rakefile +2 -2
- data/bin/multi +10 -10
- data/docs/bug-repros/91565510-repro.sh +20 -20
- data/docs/git-multirepo-cheatsheet.docx +0 -0
- data/git-multirepo.gemspec +31 -31
- data/lib/commands.rb +14 -14
- data/lib/git-multirepo.rb +2 -2
- data/lib/info.rb +4 -4
- data/lib/multirepo/commands/add-command.rb +50 -50
- data/lib/multirepo/commands/branch-command.rb +81 -81
- data/lib/multirepo/commands/checkout-command.rb +119 -119
- data/lib/multirepo/commands/clone-command.rb +67 -67
- data/lib/multirepo/commands/command.rb +89 -89
- data/lib/multirepo/commands/do-command.rb +102 -100
- data/lib/multirepo/commands/graph-command.rb +42 -42
- data/lib/multirepo/commands/init-command.rb +119 -119
- data/lib/multirepo/commands/inspect-command.rb +38 -39
- data/lib/multirepo/commands/install-command.rb +146 -137
- data/lib/multirepo/commands/merge-command.rb +225 -225
- data/lib/multirepo/commands/open-command.rb +56 -55
- data/lib/multirepo/commands/remove-command.rb +47 -47
- data/lib/multirepo/commands/uninit-command.rb +17 -17
- data/lib/multirepo/commands/update-command.rb +55 -55
- data/lib/multirepo/config.rb +15 -15
- data/lib/multirepo/files/config-entry.rb +38 -38
- data/lib/multirepo/files/config-file.rb +45 -45
- data/lib/multirepo/files/lock-entry.rb +28 -28
- data/lib/multirepo/files/lock-file.rb +55 -55
- data/lib/multirepo/files/meta-file.rb +40 -40
- data/lib/multirepo/files/tracking-file.rb +8 -8
- data/lib/multirepo/files/tracking-files.rb +46 -46
- data/lib/multirepo/git/branch.rb +31 -31
- data/lib/multirepo/git/change.rb +10 -10
- data/lib/multirepo/git/commit.rb +6 -6
- data/lib/multirepo/git/git-runner.rb +46 -46
- data/lib/multirepo/git/git.rb +9 -9
- data/lib/multirepo/git/ref.rb +37 -37
- data/lib/multirepo/git/remote.rb +16 -16
- data/lib/multirepo/git/repo.rb +122 -122
- data/lib/multirepo/hooks/post-commit-hook.rb +22 -22
- data/lib/multirepo/hooks/pre-commit-hook.rb +34 -34
- data/lib/multirepo/logic/dependency.rb +5 -5
- data/lib/multirepo/logic/merge-descriptor.rb +94 -94
- data/lib/multirepo/logic/node.rb +71 -71
- data/lib/multirepo/logic/performer.rb +56 -56
- data/lib/multirepo/logic/revision-selector.rb +34 -34
- 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 +94 -94
- 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 +2 -2
@@ -1,82 +1,82 @@
|
|
1
|
-
require "multirepo/utility/console"
|
2
|
-
require "multirepo/git/git"
|
3
|
-
require "multirepo/files/config-file"
|
4
|
-
require "multirepo/files/tracking-files"
|
5
|
-
require "multirepo/logic/performer"
|
6
|
-
|
7
|
-
module MultiRepo
|
8
|
-
class BranchCommand < Command
|
9
|
-
self.command = "branch"
|
10
|
-
self.summary = "Create and/or checkout a new branch for all repos."
|
11
|
-
|
12
|
-
def self.options
|
13
|
-
[
|
14
|
-
['<branch name>', 'The name of the branch to create and checkout.'],
|
15
|
-
['[--force]', 'Force creating the branch even if the repos contain uncommmitted changes.'],
|
16
|
-
['[--no-push]', 'Do not push the branch on creation.']
|
17
|
-
].concat(super)
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(argv)
|
21
|
-
@branch_name = argv.shift_argument
|
22
|
-
@force = argv.flag?("force")
|
23
|
-
@remote_tracking = argv.flag?("push", true)
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
def validate!
|
28
|
-
super
|
29
|
-
help! "You must specify a branch name" unless @branch_name
|
30
|
-
help! "Please provide a valid branch name" unless Git.valid_branch_name?(@branch_name)
|
31
|
-
end
|
32
|
-
|
33
|
-
def run
|
34
|
-
ensure_in_work_tree
|
35
|
-
ensure_multirepo_enabled
|
36
|
-
|
37
|
-
Console.log_step("Branching...")
|
38
|
-
|
39
|
-
main_repo = Repo.new(".")
|
40
|
-
|
41
|
-
# Ensure the main repo is clean
|
42
|
-
raise MultiRepoException, "Main repo is not clean; multi branch aborted" unless main_repo.clean?
|
43
|
-
|
44
|
-
# Ensure dependencies are clean
|
45
|
-
config_entries = ConfigFile.new(".").load_entries
|
46
|
-
unless Utils.dependencies_clean?(config_entries)
|
47
|
-
raise MultiRepoException, "Dependencies are not clean; multi branch aborted"
|
48
|
-
end
|
49
|
-
|
50
|
-
# Branch dependencies
|
51
|
-
Performer.dependencies.each do |dependency|
|
52
|
-
perform_branch(dependency.config_entry.repo)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Branch the main repo
|
56
|
-
perform_branch(main_repo)
|
57
|
-
|
58
|
-
Console.log_step("Done!")
|
59
|
-
end
|
60
|
-
|
61
|
-
def perform_branch(repo)
|
62
|
-
Console.log_substep("Branching '#{repo.path}' ...")
|
63
|
-
Console.log_info("Creating and checking out branch #{@branch_name} ...")
|
64
|
-
|
65
|
-
branch = repo.branch(@branch_name)
|
66
|
-
branch.create unless branch.exists?
|
67
|
-
branch.checkout
|
68
|
-
|
69
|
-
if Utils.is_multirepo_enabled(repo.path)
|
70
|
-
Console.log_info("Updating and committing tracking files")
|
71
|
-
tracking_files = TrackingFiles.new(repo.path)
|
72
|
-
tracking_files.update
|
73
|
-
tracking_files.commit("[multirepo] Post-branch tracking files update")
|
74
|
-
end
|
75
|
-
|
76
|
-
if @remote_tracking
|
77
|
-
Console.log_info("Pushing #{@branch_name} to origin/#{@branch_name}")
|
78
|
-
repo.branch(@branch_name).push
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
1
|
+
require "multirepo/utility/console"
|
2
|
+
require "multirepo/git/git"
|
3
|
+
require "multirepo/files/config-file"
|
4
|
+
require "multirepo/files/tracking-files"
|
5
|
+
require "multirepo/logic/performer"
|
6
|
+
|
7
|
+
module MultiRepo
|
8
|
+
class BranchCommand < Command
|
9
|
+
self.command = "branch"
|
10
|
+
self.summary = "Create and/or checkout a new branch for all repos."
|
11
|
+
|
12
|
+
def self.options
|
13
|
+
[
|
14
|
+
['<branch name>', 'The name of the branch to create and checkout.'],
|
15
|
+
['[--force]', 'Force creating the branch even if the repos contain uncommmitted changes.'],
|
16
|
+
['[--no-push]', 'Do not push the branch on creation.']
|
17
|
+
].concat(super)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(argv)
|
21
|
+
@branch_name = argv.shift_argument
|
22
|
+
@force = argv.flag?("force")
|
23
|
+
@remote_tracking = argv.flag?("push", true)
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate!
|
28
|
+
super
|
29
|
+
help! "You must specify a branch name" unless @branch_name
|
30
|
+
help! "Please provide a valid branch name" unless Git.valid_branch_name?(@branch_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
ensure_in_work_tree
|
35
|
+
ensure_multirepo_enabled
|
36
|
+
|
37
|
+
Console.log_step("Branching...")
|
38
|
+
|
39
|
+
main_repo = Repo.new(".")
|
40
|
+
|
41
|
+
# Ensure the main repo is clean
|
42
|
+
raise MultiRepoException, "Main repo is not clean; multi branch aborted" unless main_repo.clean?
|
43
|
+
|
44
|
+
# Ensure dependencies are clean
|
45
|
+
config_entries = ConfigFile.new(".").load_entries
|
46
|
+
unless Utils.dependencies_clean?(config_entries)
|
47
|
+
raise MultiRepoException, "Dependencies are not clean; multi branch aborted"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Branch dependencies
|
51
|
+
Performer.dependencies.each do |dependency|
|
52
|
+
perform_branch(dependency.config_entry.repo)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Branch the main repo
|
56
|
+
perform_branch(main_repo)
|
57
|
+
|
58
|
+
Console.log_step("Done!")
|
59
|
+
end
|
60
|
+
|
61
|
+
def perform_branch(repo)
|
62
|
+
Console.log_substep("Branching '#{repo.path}' ...")
|
63
|
+
Console.log_info("Creating and checking out branch #{@branch_name} ...")
|
64
|
+
|
65
|
+
branch = repo.branch(@branch_name)
|
66
|
+
branch.create unless branch.exists?
|
67
|
+
branch.checkout
|
68
|
+
|
69
|
+
if Utils.is_multirepo_enabled(repo.path)
|
70
|
+
Console.log_info("Updating and committing tracking files")
|
71
|
+
tracking_files = TrackingFiles.new(repo.path)
|
72
|
+
tracking_files.update
|
73
|
+
tracking_files.commit("[multirepo] Post-branch tracking files update")
|
74
|
+
end
|
75
|
+
|
76
|
+
if @remote_tracking
|
77
|
+
Console.log_info("Pushing #{@branch_name} to origin/#{@branch_name}")
|
78
|
+
repo.branch(@branch_name).push
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
82
|
end
|
@@ -1,120 +1,120 @@
|
|
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
|
-
['<refname>', '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_name = 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_name
|
28
|
-
unless validate_only_one_flag(@checkout_latest, @checkout_exact)
|
29
|
-
help! "You can't provide more than one operation modifier (--latest, --exact, etc.)"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def run
|
34
|
-
ensure_in_work_tree
|
35
|
-
|
36
|
-
# Find out the checkout mode based on command-line options
|
37
|
-
mode = RevisionSelector.mode_for_args(@checkout_latest, @checkout_exact)
|
38
|
-
|
39
|
-
strategy_name = RevisionSelectionMode.name_for_mode(mode)
|
40
|
-
Console.log_step("Checking out #{@ref_name} and its dependencies using the '#{strategy_name}' strategy...")
|
41
|
-
|
42
|
-
main_repo = Repo.new(".")
|
43
|
-
|
44
|
-
unless proceed_if_merge_commit?(main_repo, @ref_name, mode)
|
45
|
-
raise MultiRepoException, "Aborting checkout"
|
46
|
-
end
|
47
|
-
|
48
|
-
checkout_core(main_repo, mode)
|
49
|
-
|
50
|
-
Console.log_step("Done!")
|
51
|
-
end
|
52
|
-
|
53
|
-
def checkout_core(main_repo, mode)
|
54
|
-
initial_revision = main_repo.current_revision
|
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_warning("Restoring working copy to #{initial_revision}")
|
62
|
-
main_repo.checkout(initial_revision)
|
63
|
-
raise e
|
64
|
-
end
|
65
|
-
dependencies_checkout_step(mode, @ref_name)
|
66
|
-
end
|
67
|
-
|
68
|
-
def checkout_main_repo_step(main_repo)
|
69
|
-
Performer.perform_main_repo_checkout(main_repo, @ref_name)
|
70
|
-
end
|
71
|
-
|
72
|
-
def ensure_dependencies_clean_step(main_repo)
|
73
|
-
unless Utils.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_name = nil)
|
79
|
-
Performer.dependencies.each do |dependency|
|
80
|
-
# Find out the required dependency revision based on the checkout mode
|
81
|
-
revision = RevisionSelector.revision_for_mode(mode, ref_name, dependency.lock_entry)
|
82
|
-
perform_dependency_checkout(dependency.config_entry, revision)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def proceed_if_merge_commit?(main_repo, ref_name, mode)
|
87
|
-
return true unless main_repo.ref(ref_name).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
|
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
|
+
['<refname>', '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_name = 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_name
|
28
|
+
unless validate_only_one_flag(@checkout_latest, @checkout_exact)
|
29
|
+
help! "You can't provide more than one operation modifier (--latest, --exact, etc.)"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
ensure_in_work_tree
|
35
|
+
|
36
|
+
# Find out the checkout mode based on command-line options
|
37
|
+
mode = RevisionSelector.mode_for_args(@checkout_latest, @checkout_exact)
|
38
|
+
|
39
|
+
strategy_name = RevisionSelectionMode.name_for_mode(mode)
|
40
|
+
Console.log_step("Checking out #{@ref_name} and its dependencies using the '#{strategy_name}' strategy...")
|
41
|
+
|
42
|
+
main_repo = Repo.new(".")
|
43
|
+
|
44
|
+
unless proceed_if_merge_commit?(main_repo, @ref_name, mode)
|
45
|
+
raise MultiRepoException, "Aborting checkout"
|
46
|
+
end
|
47
|
+
|
48
|
+
checkout_core(main_repo, mode)
|
49
|
+
|
50
|
+
Console.log_step("Done!")
|
51
|
+
end
|
52
|
+
|
53
|
+
def checkout_core(main_repo, mode)
|
54
|
+
initial_revision = main_repo.current_revision
|
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_warning("Restoring working copy to #{initial_revision}")
|
62
|
+
main_repo.checkout(initial_revision)
|
63
|
+
raise e
|
64
|
+
end
|
65
|
+
dependencies_checkout_step(mode, @ref_name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def checkout_main_repo_step(main_repo)
|
69
|
+
Performer.perform_main_repo_checkout(main_repo, @ref_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
def ensure_dependencies_clean_step(main_repo)
|
73
|
+
unless Utils.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_name = nil)
|
79
|
+
Performer.dependencies.each do |dependency|
|
80
|
+
# Find out the required dependency revision based on the checkout mode
|
81
|
+
revision = RevisionSelector.revision_for_mode(mode, ref_name, dependency.lock_entry)
|
82
|
+
perform_dependency_checkout(dependency.config_entry, revision)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def proceed_if_merge_commit?(main_repo, ref_name, mode)
|
87
|
+
return true unless main_repo.ref(ref_name).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
|
120
120
|
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
require "multirepo/utility/console"
|
2
|
-
require "multirepo/utility/utils"
|
3
|
-
require "multirepo/git/repo"
|
4
|
-
require_relative "install-command"
|
5
|
-
|
6
|
-
module MultiRepo
|
7
|
-
class CloneCommand < Command
|
8
|
-
self.command = "clone"
|
9
|
-
self.summary = "Clones the specified repository in a subfolder, then installs it."
|
10
|
-
|
11
|
-
def self.options
|
12
|
-
[
|
13
|
-
['<url>', 'The repository to clone.'],
|
14
|
-
['<name>', 'The name of the containing folder that will be created.'],
|
15
|
-
['[<refname>]', 'The branch, tag or commit id to checkout. Checkout will use "master" if unspecified.']
|
16
|
-
].concat(super)
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(argv)
|
20
|
-
@url = argv.shift_argument
|
21
|
-
@name = argv.shift_argument
|
22
|
-
@ref_name = argv.shift_argument || "master"
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
|
-
def validate!
|
27
|
-
super
|
28
|
-
help! "You must specify a repository to clone" unless @url
|
29
|
-
help! "You must specify a containing folder name" unless @name
|
30
|
-
end
|
31
|
-
|
32
|
-
def run
|
33
|
-
Console.log_step("Cloning #{@url} ...")
|
34
|
-
|
35
|
-
raise MultiRepoException, "A directory named #{@name} already exists" if Dir.exists?(@name)
|
36
|
-
|
37
|
-
main_repo_path = "#{@name}/#{@name}"
|
38
|
-
main_repo = Repo.new(main_repo_path)
|
39
|
-
|
40
|
-
# Recursively create the directory where we'll clone the main repo
|
41
|
-
FileUtils.mkpath(main_repo_path)
|
42
|
-
|
43
|
-
# Clone the specified remote in the just-created directory
|
44
|
-
raise MultiRepoException, "Could not clone repo from #{@url}" unless main_repo.clone(@url)
|
45
|
-
|
46
|
-
# Checkout the specified main repo ref so that install reads the proper config file
|
47
|
-
unless main_repo.checkout(@ref_name)
|
48
|
-
raise MultiRepoException, "Couldn't perform checkout of main repo #{@ref_name}!"
|
49
|
-
end
|
50
|
-
|
51
|
-
Console.log_substep("Checked out main repo #{@ref_name}")
|
52
|
-
|
53
|
-
# Make sure the ref we just checked out is tracked by multirepo
|
54
|
-
unless Utils.is_multirepo_tracked(main_repo_path)
|
55
|
-
raise MultiRepoException, "Ref #{@ref_name} is not tracked by multirepo"
|
56
|
-
end
|
57
|
-
|
58
|
-
# Install
|
59
|
-
original_path = Dir.pwd
|
60
|
-
Dir.chdir(main_repo_path)
|
61
|
-
install_command = InstallCommand.new(CLAide::ARGV.new([]))
|
62
|
-
install_command.full_install
|
63
|
-
Dir.chdir(original_path)
|
64
|
-
|
65
|
-
Console.log_step("Done!")
|
66
|
-
end
|
67
|
-
end
|
1
|
+
require "multirepo/utility/console"
|
2
|
+
require "multirepo/utility/utils"
|
3
|
+
require "multirepo/git/repo"
|
4
|
+
require_relative "install-command"
|
5
|
+
|
6
|
+
module MultiRepo
|
7
|
+
class CloneCommand < Command
|
8
|
+
self.command = "clone"
|
9
|
+
self.summary = "Clones the specified repository in a subfolder, then installs it."
|
10
|
+
|
11
|
+
def self.options
|
12
|
+
[
|
13
|
+
['<url>', 'The repository to clone.'],
|
14
|
+
['<name>', 'The name of the containing folder that will be created.'],
|
15
|
+
['[<refname>]', 'The branch, tag or commit id to checkout. Checkout will use "master" if unspecified.']
|
16
|
+
].concat(super)
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(argv)
|
20
|
+
@url = argv.shift_argument
|
21
|
+
@name = argv.shift_argument
|
22
|
+
@ref_name = argv.shift_argument || "master"
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate!
|
27
|
+
super
|
28
|
+
help! "You must specify a repository to clone" unless @url
|
29
|
+
help! "You must specify a containing folder name" unless @name
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
Console.log_step("Cloning #{@url} ...")
|
34
|
+
|
35
|
+
raise MultiRepoException, "A directory named #{@name} already exists" if Dir.exists?(@name)
|
36
|
+
|
37
|
+
main_repo_path = "#{@name}/#{@name}"
|
38
|
+
main_repo = Repo.new(main_repo_path)
|
39
|
+
|
40
|
+
# Recursively create the directory where we'll clone the main repo
|
41
|
+
FileUtils.mkpath(main_repo_path)
|
42
|
+
|
43
|
+
# Clone the specified remote in the just-created directory
|
44
|
+
raise MultiRepoException, "Could not clone repo from #{@url}" unless main_repo.clone(@url)
|
45
|
+
|
46
|
+
# Checkout the specified main repo ref so that install reads the proper config file
|
47
|
+
unless main_repo.checkout(@ref_name)
|
48
|
+
raise MultiRepoException, "Couldn't perform checkout of main repo #{@ref_name}!"
|
49
|
+
end
|
50
|
+
|
51
|
+
Console.log_substep("Checked out main repo #{@ref_name}")
|
52
|
+
|
53
|
+
# Make sure the ref we just checked out is tracked by multirepo
|
54
|
+
unless Utils.is_multirepo_tracked(main_repo_path)
|
55
|
+
raise MultiRepoException, "Ref #{@ref_name} is not tracked by multirepo"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Install
|
59
|
+
original_path = Dir.pwd
|
60
|
+
Dir.chdir(main_repo_path)
|
61
|
+
install_command = InstallCommand.new(CLAide::ARGV.new([]))
|
62
|
+
install_command.full_install
|
63
|
+
Dir.chdir(original_path)
|
64
|
+
|
65
|
+
Console.log_step("Done!")
|
66
|
+
end
|
67
|
+
end
|
68
68
|
end
|