git-multirepo 1.0.0.beta27 → 1.0.0.beta29

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,88 +1,105 @@
1
- require "multirepo/utility/console"
2
- require "multirepo/utility/utils"
3
- require "multirepo/git/repo"
4
- require "multirepo/commands/checkout-command"
5
-
6
- module MultiRepo
7
- class InstallCommand < Command
8
- self.command = "install"
9
- self.summary = "Clones and checks out dependencies as defined in the version-controlled multirepo metadata files and installs git-multirepo's local git hooks."
10
-
11
- def self.options
12
- [['[--hooks]', 'Only install local git hooks.']].concat(super)
13
- end
14
-
15
- def initialize(argv)
16
- @hooks = argv.flag?("hooks")
17
- super
18
- end
19
-
20
- def run
21
- validate_in_work_tree
22
- ensure_multirepo_tracked
23
-
24
- if @hooks
25
- Console.log_step("Installing hooks in main repo and all dependencies...")
26
- install_hooks_step
27
- else
28
- Console.log_step("Cloning dependencies and installing hooks...")
29
- install_dependencies_step
30
- end
31
-
32
- Console.log_step("Done!")
33
- rescue MultiRepoException => e
34
- Console.log_error(e.message)
35
- end
36
-
37
- def install_dependencies_step
38
- # Read config entries as-is on disk, without prior checkout
39
- config_entries = ConfigFile.load
40
- Console.log_substep("Installing #{config_entries.count} dependencies...");
41
-
42
- # Clone or fetch all configured dependencies to make sure nothing is missing locally
43
- config_entries.each { |entry| clone_or_fetch(entry) }
44
-
45
- # Checkout the appropriate branches as specified in the lock file
46
- checkout_command = CheckoutCommand.new(CLAide::ARGV.new([]))
47
- checkout_command.dependencies_checkout_step(CheckoutCommand::CheckoutMode::LATEST)
48
-
49
- install_hooks_step
50
- end
51
-
52
- def install_hooks_step
53
- install_hooks
54
- Console.log_substep("Installed git hooks in main repo")
55
-
56
- install_hooks_in_multirepo_enabled_dependencies
57
- end
58
-
59
- def clone_or_fetch(entry)
60
- if entry.repo.exists?
61
- check_repo_validity(entry)
62
- fetch_repo(entry)
63
- else
64
- clone_repo(entry)
65
- end
66
- end
67
-
68
- # Repo operations
69
-
70
- def fetch_repo(entry)
71
- Console.log_substep("Working copy '#{entry.repo.path}' already exists, fetching instead...")
72
- raise MultiRepoException, "Could not fetch from remote #{entry.repo.remote('origin').url}" unless entry.repo.fetch
73
- end
74
-
75
- def clone_repo(entry)
76
- Console.log_substep("Cloning #{entry.url} into '#{entry.repo.path}'")
77
- raise MultiRepoException, "Could not clone remote #{entry.url}" unless entry.repo.clone(entry.url)
78
- end
79
-
80
- # Validation
81
-
82
- def check_repo_validity(entry)
83
- unless entry.repo.remote("origin").url == entry.url
84
- raise MultiRepoException, "'#{entry.path}' origin URL (#{entry.repo.remote('origin').url}) does not match entry (#{entry.url})!"
85
- end
86
- end
87
- end
1
+ require "multirepo/utility/console"
2
+ require "multirepo/utility/utils"
3
+ require "multirepo/git/repo"
4
+ require "multirepo/commands/checkout-command"
5
+
6
+ module MultiRepo
7
+ class InstallCommand < Command
8
+ self.command = "install"
9
+ self.summary = "Clones and checks out dependencies as defined in the version-controlled multirepo metadata files and installs git-multirepo's local git hooks."
10
+
11
+ def self.options
12
+ [['[--hooks]', 'Only install local git hooks.']].concat(super)
13
+ end
14
+
15
+ def initialize(argv)
16
+ @hooks = argv.flag?("hooks")
17
+ super
18
+ end
19
+
20
+ def run
21
+ validate_in_work_tree
22
+ ensure_multirepo_tracked
23
+
24
+ if @hooks
25
+ Console.log_step("Installing hooks in main repo and all dependencies...")
26
+ install_hooks_step
27
+ else
28
+ Console.log_step("Cloning dependencies and installing hooks...")
29
+ full_install
30
+ end
31
+
32
+ Console.log_step("Done!")
33
+ rescue MultiRepoException => e
34
+ Console.log_error(e.message)
35
+ end
36
+
37
+ def full_install
38
+ install_dependencies_step
39
+ install_hooks_step
40
+ update_gitconfigs_step
41
+ end
42
+
43
+ def install_dependencies_step
44
+ # Read config entries as-is on disk, without prior checkout
45
+ config_entries = ConfigFile.load
46
+ Console.log_substep("Installing #{config_entries.count} dependencies...");
47
+
48
+ # Clone or fetch all configured dependencies to make sure nothing is missing locally
49
+ config_entries.each { |entry| clone_or_fetch(entry) }
50
+
51
+ # Checkout the appropriate branches as specified in the lock file
52
+ checkout_command = CheckoutCommand.new(CLAide::ARGV.new([]))
53
+ checkout_command.dependencies_checkout_step(CheckoutCommand::CheckoutMode::LATEST)
54
+ end
55
+
56
+ def install_hooks_step
57
+ install_hooks(".")
58
+ Console.log_substep("Installed git hooks in main repo")
59
+
60
+ multirepo_enabled_dependencies.each do |entry|
61
+ install_hooks(entry.repo.path)
62
+ Console.log_substep("Installed hooks in multirepo-enabled dependency '#{entry.repo.path}'")
63
+ end
64
+ end
65
+
66
+ def update_gitconfigs_step
67
+ update_gitconfig(".")
68
+ Console.log_substep("Updated .git/config file")
69
+
70
+ multirepo_enabled_dependencies.each do |entry|
71
+ update_gitconfig(entry.repo.path)
72
+ Console.log_substep("Updated .git/config in multirepo-enabled dependency '#{entry.repo.path}'")
73
+ end
74
+ end
75
+
76
+ def clone_or_fetch(entry)
77
+ if entry.repo.exists?
78
+ check_repo_validity(entry)
79
+ fetch_repo(entry)
80
+ else
81
+ clone_repo(entry)
82
+ end
83
+ end
84
+
85
+ # Repo operations
86
+
87
+ def fetch_repo(entry)
88
+ Console.log_substep("Working copy '#{entry.repo.path}' already exists, fetching instead...")
89
+ raise MultiRepoException, "Could not fetch from remote #{entry.repo.remote('origin').url}" unless entry.repo.fetch
90
+ end
91
+
92
+ def clone_repo(entry)
93
+ Console.log_substep("Cloning #{entry.url} into '#{entry.repo.path}'")
94
+ raise MultiRepoException, "Could not clone remote #{entry.url}" unless entry.repo.clone(entry.url)
95
+ end
96
+
97
+ # Validation
98
+
99
+ def check_repo_validity(entry)
100
+ unless entry.repo.remote("origin").url == entry.url
101
+ raise MultiRepoException, "'#{entry.path}' origin URL (#{entry.repo.remote('origin').url}) does not match entry (#{entry.url})!"
102
+ end
103
+ end
104
+ end
88
105
  end
@@ -1,26 +1,26 @@
1
- require "os"
2
-
3
- require "multirepo/utility/console"
4
- require "multirepo/utility/utils"
5
-
6
- module MultiRepo
7
- class OpenCommand < Command
8
- self.command = "open"
9
- self.summary = "Opens all dependencies in the current OS's file explorer."
10
-
11
- def run
12
- validate_in_work_tree
13
- ensure_multirepo_enabled
14
-
15
- ConfigFile.load.each do |entry|
16
- if OS.osx?
17
- `open "#{entry.repo.path}"`
18
- elsif OS.windows?
19
- `explorer "#{Utils.convert_to_windows_path(entry.repo.path)}"`
20
- end
21
- end
22
- rescue MultiRepoException => e
23
- Console.log_error(e.message)
24
- end
25
- end
1
+ require "os"
2
+
3
+ require "multirepo/utility/console"
4
+ require "multirepo/utility/utils"
5
+
6
+ module MultiRepo
7
+ class OpenCommand < Command
8
+ self.command = "open"
9
+ self.summary = "Opens all dependencies in the current OS's file explorer."
10
+
11
+ def run
12
+ validate_in_work_tree
13
+ ensure_multirepo_enabled
14
+
15
+ ConfigFile.load.each do |entry|
16
+ if OS.osx?
17
+ `open "#{entry.repo.path}"`
18
+ elsif OS.windows?
19
+ `explorer "#{Utils.convert_to_windows_path(entry.repo.path)}"`
20
+ end
21
+ end
22
+ rescue MultiRepoException => e
23
+ Console.log_error(e.message)
24
+ end
25
+ end
26
26
  end
@@ -1,49 +1,49 @@
1
- require "multirepo/utility/console"
2
- require "multirepo/files/config-file"
3
-
4
- module MultiRepo
5
- class RemoveCommand < Command
6
- self.command = "remove"
7
- self.summary = "Removes the specified dependency from multirepo."
8
-
9
- def self.options
10
- [
11
- ['<path>', 'The relative path to the dependency to remove (e.g. ../MyOldDependency).'],
12
- ['[--delete]', 'Delete the dependency on disk in addition to removing it from the multirepo config.']
13
- ].concat(super)
14
- end
15
-
16
- def initialize(argv)
17
- @path = argv.shift_argument
18
- @delete = argv.flag?("delete")
19
- super
20
- end
21
-
22
- def validate!
23
- super
24
- help! "You must specify a dependency repository to remove" unless @path
25
- end
26
-
27
- def run
28
- validate_in_work_tree
29
- ensure_multirepo_enabled
30
-
31
- repo = Repo.new(@path)
32
- entry = ConfigEntry.new(repo)
33
-
34
- if ConfigFile.entry_exists?(entry)
35
- ConfigFile.remove_entry(entry)
36
- Console.log_step("Removed '#{@path}' from the .multirepo file")
37
-
38
- if @delete
39
- FileUtils.rm_rf(@path)
40
- Console.log_step("Deleted '#{@path}' from disk")
41
- end
42
- else
43
- raise MultiRepoException, "'#{@path}' isn't tracked by multirepo"
44
- end
45
- rescue MultiRepoException => e
46
- Console.log_error(e.message)
47
- end
48
- end
1
+ require "multirepo/utility/console"
2
+ require "multirepo/files/config-file"
3
+
4
+ module MultiRepo
5
+ class RemoveCommand < Command
6
+ self.command = "remove"
7
+ self.summary = "Removes the specified dependency from multirepo."
8
+
9
+ def self.options
10
+ [
11
+ ['<path>', 'The relative path to the dependency to remove (e.g. ../MyOldDependency).'],
12
+ ['[--delete]', 'Delete the dependency on disk in addition to removing it from the multirepo config.']
13
+ ].concat(super)
14
+ end
15
+
16
+ def initialize(argv)
17
+ @path = argv.shift_argument
18
+ @delete = argv.flag?("delete")
19
+ super
20
+ end
21
+
22
+ def validate!
23
+ super
24
+ help! "You must specify a dependency repository to remove" unless @path
25
+ end
26
+
27
+ def run
28
+ validate_in_work_tree
29
+ ensure_multirepo_enabled
30
+
31
+ repo = Repo.new(@path)
32
+ entry = ConfigEntry.new(repo)
33
+
34
+ if ConfigFile.entry_exists?(entry)
35
+ ConfigFile.remove_entry(entry)
36
+ Console.log_step("Removed '#{@path}' from the .multirepo file")
37
+
38
+ if @delete
39
+ FileUtils.rm_rf(@path)
40
+ Console.log_step("Deleted '#{@path}' from disk")
41
+ end
42
+ else
43
+ raise MultiRepoException, "'#{@path}' isn't tracked by multirepo"
44
+ end
45
+ rescue MultiRepoException => e
46
+ Console.log_error(e.message)
47
+ end
48
+ end
49
49
  end
@@ -1,20 +1,20 @@
1
- require "multirepo/utility/console"
2
-
3
- module MultiRepo
4
- class UninitCommand < Command
5
- self.command = "uninit"
6
- self.summary = "Removes all traces of multirepo in the current multirepo repository."
7
-
8
- def run
9
- validate_in_work_tree
10
-
11
- File.delete(".multirepo")
12
- File.delete(".multirepo.lock")
13
- uninstall_hooks
14
-
15
- Console.log_step("All traces of multirepo have been removed from this repository")
16
- rescue MultiRepoException => e
17
- Console.log_error(e.message)
18
- end
19
- end
1
+ require "multirepo/utility/console"
2
+
3
+ module MultiRepo
4
+ class UninitCommand < Command
5
+ self.command = "uninit"
6
+ self.summary = "Removes all traces of multirepo in the current multirepo repository."
7
+
8
+ def run
9
+ validate_in_work_tree
10
+
11
+ File.delete(".multirepo")
12
+ File.delete(".multirepo.lock")
13
+ uninstall_hooks
14
+
15
+ Console.log_step("All traces of multirepo have been removed from this repository")
16
+ rescue MultiRepoException => e
17
+ Console.log_error(e.message)
18
+ end
19
+ end
20
20
  end
@@ -1,48 +1,54 @@
1
- require "multirepo/utility/console"
2
-
3
- module MultiRepo
4
- class UpdateCommand < Command
5
- self.command = "update"
6
- self.summary = "Force-updates the multirepo lock file."
7
-
8
- def self.options
9
- [
10
- ['[--force]', 'Update the lock file even if dependencies contain uncommitted changes.'],
11
- ['[--commit]', 'Commit the lock file after updating it.']
12
- ].concat(super)
13
- end
14
-
15
- def initialize(argv)
16
- @commit = argv.flag?("commit")
17
- @force = argv.flag?("force")
18
- super
19
- end
20
-
21
- def run
22
- validate_in_work_tree
23
- ensure_multirepo_enabled
24
-
25
- Console.log_step("Updating...")
26
-
27
- dependencies_clean = Utils.ensure_dependencies_clean(ConfigFile.load)
28
- if dependencies_clean
29
- LockFile.update
30
- Console.log_substep("Updated lock file with latest dependency commits")
31
- elsif !dependencies_clean && @force
32
- LockFile.update
33
- Console.log_warning("Updated lock file with latest dependency commits regardless of uncommitted changes")
34
- else
35
- raise MultiRepoException, "Can't update because not all dependencies are clean"
36
- end
37
-
38
- if @commit
39
- Console.log_substep("Committing updated lock file")
40
- LockFile.commit
41
- end
42
-
43
- Console.log_step("Done!")
44
- rescue MultiRepoException => e
45
- Console.log_error(e.message)
46
- end
47
- end
1
+ require "multirepo/utility/console"
2
+
3
+ module MultiRepo
4
+ class UpdateCommand < Command
5
+ self.command = "update"
6
+ self.summary = "Force-updates the multirepo lock file."
7
+
8
+ def self.options
9
+ [
10
+ ['[--force]', 'Update the lock file even if dependencies contain uncommitted changes.'],
11
+ ['[--commit]', 'Commit the lock file after updating it.']
12
+ ].concat(super)
13
+ end
14
+
15
+ def initialize(argv)
16
+ @commit = argv.flag?("commit")
17
+ @force = argv.flag?("force")
18
+ super
19
+ end
20
+
21
+ def run
22
+ validate_in_work_tree
23
+ ensure_multirepo_enabled
24
+
25
+ Console.log_step("Updating...")
26
+
27
+ dependencies_clean = Utils.ensure_dependencies_clean(ConfigFile.load)
28
+ if dependencies_clean
29
+ update_lock_file_step("Updated lock file with latest dependency commits")
30
+ elsif !dependencies_clean && @force
31
+ update_lock_file_step("Force-updated lock file with latest dependency commits (ignoring uncommitted changes)")
32
+ else
33
+ raise MultiRepoException, "Can't update because not all dependencies are clean"
34
+ end
35
+
36
+ Console.log_step("Done!")
37
+ rescue MultiRepoException => e
38
+ Console.log_error(e.message)
39
+ end
40
+
41
+ def update_lock_file_step(log_message)
42
+ changed = LockFile.update
43
+
44
+ if changed && @commit
45
+ Console.log_substep("Committing updated lock file")
46
+ LockFile.commit("[multirepo] Manually updated lock file")
47
+ elsif changed
48
+ Console.log_substep(log_message)
49
+ else
50
+ Console.log_info("Lock file is already up-to-date")
51
+ end
52
+ end
53
+ end
48
54
  end