git-multirepo 1.0.0.beta16 → 1.0.0.beta17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) 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 +37 -37
  6. data/LICENSE +22 -22
  7. data/README.md +139 -137
  8. data/Rakefile +2 -2
  9. data/bin/multi +5 -5
  10. data/git-multirepo.gemspec +29 -29
  11. data/lib/commands.rb +12 -12
  12. data/lib/git-multirepo.rb +2 -1
  13. data/lib/info.rb +4 -4
  14. data/lib/multirepo/commands/add-command.rb +51 -44
  15. data/lib/multirepo/commands/branch-command.rb +52 -52
  16. data/lib/multirepo/commands/checkout-command.rb +84 -84
  17. data/lib/multirepo/commands/clone-command.rb +53 -53
  18. data/lib/multirepo/commands/command.rb +32 -36
  19. data/lib/multirepo/commands/edit-command.rb +21 -21
  20. data/lib/multirepo/commands/fetch-command.rb +23 -23
  21. data/lib/multirepo/commands/init-command.rb +53 -53
  22. data/lib/multirepo/commands/install-command.rb +68 -68
  23. data/lib/multirepo/commands/open-command.rb +25 -25
  24. data/lib/multirepo/commands/remove-command.rb +48 -48
  25. data/lib/multirepo/commands/uninit-command.rb +21 -20
  26. data/lib/multirepo/commands/update-command.rb +50 -50
  27. data/lib/multirepo/config.rb +12 -12
  28. data/lib/multirepo/files/config-entry.rb +37 -37
  29. data/lib/multirepo/files/config-file.rb +37 -37
  30. data/lib/multirepo/files/lock-entry.rb +25 -25
  31. data/lib/multirepo/files/lock-file.rb +39 -38
  32. data/lib/multirepo/git/branch.rb +27 -27
  33. data/lib/multirepo/git/change.rb +10 -10
  34. data/lib/multirepo/git/git.rb +38 -38
  35. data/lib/multirepo/git/remote.rb +15 -15
  36. data/lib/multirepo/git/repo.rb +66 -66
  37. data/lib/multirepo/hooks/post-merge-hook.rb +18 -0
  38. data/lib/multirepo/hooks/pre-commit-hook.rb +23 -23
  39. data/lib/multirepo/multirepo-exception.rb +5 -5
  40. data/lib/multirepo/utility/console.rb +51 -51
  41. data/lib/multirepo/utility/runner.rb +32 -32
  42. data/lib/multirepo/utility/utils.rb +41 -41
  43. data/resources/post-merge +6 -0
  44. data/resources/pre-commit +5 -5
  45. data/spec/integration/init_spec.rb +26 -22
  46. data/spec/spec_helper.rb +89 -89
  47. metadata +5 -3
@@ -1,54 +1,54 @@
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
- ].concat(super)
16
- end
17
-
18
- def initialize(argv)
19
- @url = argv.shift_argument
20
- @name = argv.shift_argument
21
- super
22
- end
23
-
24
- def validate!
25
- super
26
- help! "You must specify a repository to clone" unless @url
27
- help! "You must specify a containing folder name" unless @name
28
- end
29
-
30
- def run
31
- Console.log_step("Cloning #{@url} ...")
32
-
33
- raise MultiRepoException, "A directory named #{@name} already exists" if Dir.exists?(@name)
34
-
35
- main_repo_path = "#{@name}/#{@name}"
36
-
37
- FileUtils.mkpath(main_repo_path)
38
-
39
- main_repo = Repo.new(main_repo_path)
40
- main_repo.clone(@url)
41
-
42
- original_path = Dir.pwd
43
- Dir.chdir(main_repo_path)
44
-
45
- InstallCommand.new(CLAide::ARGV.new([])).install_internal
46
-
47
- Dir.chdir(original_path)
48
-
49
- Console.log_step("Done!")
50
- rescue MultiRepoException => e
51
- Console.log_error(e.message)
52
- end
53
- 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
+ ].concat(super)
16
+ end
17
+
18
+ def initialize(argv)
19
+ @url = argv.shift_argument
20
+ @name = argv.shift_argument
21
+ super
22
+ end
23
+
24
+ def validate!
25
+ super
26
+ help! "You must specify a repository to clone" unless @url
27
+ help! "You must specify a containing folder name" unless @name
28
+ end
29
+
30
+ def run
31
+ Console.log_step("Cloning #{@url} ...")
32
+
33
+ raise MultiRepoException, "A directory named #{@name} already exists" if Dir.exists?(@name)
34
+
35
+ main_repo_path = "#{@name}/#{@name}"
36
+
37
+ FileUtils.mkpath(main_repo_path)
38
+
39
+ main_repo = Repo.new(main_repo_path)
40
+ main_repo.clone(@url)
41
+
42
+ original_path = Dir.pwd
43
+ Dir.chdir(main_repo_path)
44
+
45
+ InstallCommand.new(CLAide::ARGV.new([])).install_internal
46
+
47
+ Dir.chdir(original_path)
48
+
49
+ Console.log_step("Done!")
50
+ rescue MultiRepoException => e
51
+ Console.log_error(e.message)
52
+ end
53
+ end
54
54
  end
@@ -1,37 +1,33 @@
1
- require "claide"
2
-
3
- require "info"
4
- require "multirepo/multirepo-exception"
5
- require "multirepo/config"
6
-
7
- module MultiRepo
8
- class Command < CLAide::Command
9
- self.abstract_command = true
10
- self.command = "multi"
11
- self.version = VERSION
12
- self.description = DESCRIPTION
13
-
14
- def initialize(argv)
15
- Config.instance.verbose = argv.flag?("verbose") ? true : false
16
- super
17
- end
18
-
19
- def validate_in_work_tree
20
- raise MultiRepoException, "Not a git repository" unless Git.is_inside_git_repo(".")
21
- end
22
-
23
- def install_pre_commit_hook
24
- Utils.install_pre_commit_hook
25
- Console.log_substep("Installed pre-commit hook")
26
- end
27
-
28
- def update_lock_file
29
- LockFile.update
30
- Console.log_substep("Updated and staged lock file with current HEAD revisions for all dependencies")
31
- end
32
-
33
- def ensure_multirepo_initialized
34
- raise MultiRepoException, "multirepo is not initialized in this repository." unless ConfigFile.exists?
35
- end
36
- end
1
+ require "claide"
2
+
3
+ require "info"
4
+ require "multirepo/multirepo-exception"
5
+ require "multirepo/config"
6
+
7
+ module MultiRepo
8
+ class Command < CLAide::Command
9
+ self.abstract_command = true
10
+ self.command = "multi"
11
+ self.version = VERSION
12
+ self.description = DESCRIPTION
13
+
14
+ def initialize(argv)
15
+ Config.instance.verbose = argv.flag?("verbose") ? true : false
16
+ super
17
+ end
18
+
19
+ def validate_in_work_tree
20
+ raise MultiRepoException, "Not a git repository" unless Git.is_inside_git_repo(".")
21
+ end
22
+
23
+ def install_hooks
24
+ Utils.install_hook("pre-commit")
25
+ Utils.install_hook("post-merge")
26
+ Console.log_substep("Installed git hooks")
27
+ end
28
+
29
+ def ensure_multirepo_initialized
30
+ raise MultiRepoException, "multirepo is not initialized in this repository." unless ConfigFile.exists?
31
+ end
32
+ end
37
33
  end
@@ -1,22 +1,22 @@
1
- require "os"
2
-
3
- module MultiRepo
4
- class EditCommand < Command
5
- self.command = "edit"
6
- self.summary = "Opens the .multirepo file in the default text editor."
7
-
8
- def run
9
- validate_in_work_tree
10
- ensure_multirepo_initialized
11
-
12
- if OS.posix?
13
- editor = `echo ${FCEDIT:-${VISUAL:-${EDITOR:-vi}}}`.strip
14
- system(editor, ".multirepo")
15
- elsif OS.windows?
16
- raise MultiRepoException, "The edit command is not implemented on Window yet."
17
- end
18
- rescue MultiRepoException => e
19
- Console.log_error(e.message)
20
- end
21
- end
1
+ require "os"
2
+
3
+ module MultiRepo
4
+ class EditCommand < Command
5
+ self.command = "edit"
6
+ self.summary = "Opens the .multirepo file in the default text editor."
7
+
8
+ def run
9
+ validate_in_work_tree
10
+ ensure_multirepo_initialized
11
+
12
+ if OS.posix?
13
+ editor = `echo ${FCEDIT:-${VISUAL:-${EDITOR:-vi}}}`.strip
14
+ system(editor, ".multirepo")
15
+ elsif OS.windows?
16
+ raise MultiRepoException, "The edit command is not implemented on Window yet."
17
+ end
18
+ rescue MultiRepoException => e
19
+ Console.log_error(e.message)
20
+ end
21
+ end
22
22
  end
@@ -1,24 +1,24 @@
1
- require "multirepo/utility/console"
2
-
3
- module MultiRepo
4
- class FetchCommand < Command
5
- self.command = "fetch"
6
- self.summary = "Performs a git fetch on all dependencies."
7
-
8
- def run
9
- validate_in_work_tree
10
- ensure_multirepo_initialized
11
-
12
- Console.log_step("Fetching dependencies...")
13
-
14
- ConfigFile.load.each do |entry|
15
- Console.log_substep("Fetching from #{entry.repo.remote('origin').url}...")
16
- entry.repo.fetch
17
- end
18
-
19
- Console.log_step("Done!")
20
- rescue MultiRepoException => e
21
- Console.log_error(e.message)
22
- end
23
- end
1
+ require "multirepo/utility/console"
2
+
3
+ module MultiRepo
4
+ class FetchCommand < Command
5
+ self.command = "fetch"
6
+ self.summary = "Performs a git fetch on all dependencies."
7
+
8
+ def run
9
+ validate_in_work_tree
10
+ ensure_multirepo_initialized
11
+
12
+ Console.log_step("Fetching dependencies...")
13
+
14
+ ConfigFile.load.each do |entry|
15
+ Console.log_substep("Fetching from #{entry.repo.remote('origin').url}...")
16
+ entry.repo.fetch
17
+ end
18
+
19
+ Console.log_step("Done!")
20
+ rescue MultiRepoException => e
21
+ Console.log_error(e.message)
22
+ end
23
+ end
24
24
  end
@@ -1,54 +1,54 @@
1
- require "multirepo/utility/console"
2
- require "multirepo/utility/utils"
3
- require "multirepo/files/config-file"
4
- require "multirepo/files/lock-file"
5
- require "multirepo/commands/command"
6
-
7
- module MultiRepo
8
- class InitCommand < Command
9
- self.command = "init"
10
- self.summary = "Initialize the current repository as a multirepo project."
11
-
12
- def run
13
- validate_in_work_tree
14
- Console.log_step("Initializing new multirepo config...")
15
-
16
- if ConfigFile.exists?
17
- return unless Console.ask_yes_no(".multirepo file already exists. Reinitialize?")
18
- end
19
-
20
- sibling_repos = Utils.sibling_repos
21
-
22
- if sibling_repos.any?
23
- entries = []
24
- sibling_repos.each do |repo|
25
- if Console.ask_yes_no("Do you want to add '#{repo.path}' (#{repo.remote('origin').url} #{repo.current_branch}) as a dependency?")
26
- entries.push(ConfigEntry.new(repo))
27
- Console.log_substep("Added the repository '#{repo.path}' to the .multirepo file")
28
- end
29
- end
30
-
31
- ConfigFile.save(entries)
32
- ConfigFile.stage
33
-
34
- dependencies_clean = Utils.ensure_dependencies_clean(entries)
35
- raise MultiRepoException, "Can't finish initialization!" unless dependencies_clean
36
-
37
- self.update_lock_file
38
- else
39
- Console.log_info("There are no sibling repositories to add")
40
- end
41
-
42
- self.install_pre_commit_hook
43
-
44
- Console.log_step("Done!")
45
- rescue MultiRepoException => e
46
- Console.log_error(e.message)
47
- end
48
-
49
- def check_repo_exists
50
- if !Dir.exists?(@repo.path) then raise MultiRepoException, "There is no folder at path '#{@repo.path}'" end
51
- if !@repo.exists? then raise MultiRepoException, "'#{@repo.path}' is not a repository" end
52
- end
53
- end
1
+ require "multirepo/utility/console"
2
+ require "multirepo/utility/utils"
3
+ require "multirepo/files/config-file"
4
+ require "multirepo/files/lock-file"
5
+ require "multirepo/commands/command"
6
+
7
+ module MultiRepo
8
+ class InitCommand < Command
9
+ self.command = "init"
10
+ self.summary = "Initialize the current repository as a multirepo project."
11
+
12
+ def run
13
+ validate_in_work_tree
14
+ Console.log_step("Initializing new multirepo config...")
15
+
16
+ if ConfigFile.exists?
17
+ return unless Console.ask_yes_no(".multirepo file already exists. Reinitialize?")
18
+ end
19
+
20
+ sibling_repos = Utils.sibling_repos
21
+
22
+ if sibling_repos.any?
23
+ entries = []
24
+ sibling_repos.each do |repo|
25
+ if Console.ask_yes_no("Do you want to add '#{repo.path}' (#{repo.remote('origin').url} #{repo.current_branch}) as a dependency?")
26
+ entries.push(ConfigEntry.new(repo))
27
+ Console.log_substep("Added the repository '#{repo.path}' to the .multirepo file")
28
+ end
29
+ end
30
+
31
+ ConfigFile.save(entries)
32
+ ConfigFile.stage
33
+
34
+ dependencies_clean = Utils.ensure_dependencies_clean(entries)
35
+ raise MultiRepoException, "Can't finish initialization!" unless dependencies_clean
36
+
37
+ LockFile.update
38
+ else
39
+ Console.log_info("There are no sibling repositories to add")
40
+ end
41
+
42
+ install_hooks
43
+
44
+ Console.log_step("Done!")
45
+ rescue MultiRepoException => e
46
+ Console.log_error(e.message)
47
+ end
48
+
49
+ def check_repo_exists
50
+ if !Dir.exists?(@repo.path) then raise MultiRepoException, "There is no folder at path '#{@repo.path}'" end
51
+ if !@repo.exists? then raise MultiRepoException, "'#{@repo.path}' is not a repository" end
52
+ end
53
+ end
54
54
  end
@@ -1,69 +1,69 @@
1
- require "multirepo/utility/console"
2
- require "multirepo/utility/utils"
3
- require "multirepo/git/repo"
4
-
5
- module MultiRepo
6
- class InstallCommand < Command
7
- self.command = "install"
8
- self.summary = "Clones and checks out dependencies as defined in the .multirepo file, and installs git-multirepo's local pre-commit hook."
9
-
10
- def run
11
- validate_in_work_tree
12
- ensure_multirepo_initialized
13
-
14
- Console.log_step("Cloning dependencies and installing hook...")
15
-
16
- install_internal
17
-
18
- Console.log_step("Done!")
19
- rescue MultiRepoException => e
20
- Console.log_error(e.message)
21
- end
22
-
23
- def install_internal
24
- config_entries = ConfigFile.load
25
-
26
- Console.log_substep("Installing #{config_entries.count} dependencies...");
27
-
28
- config_entries.each { |e| install(e) }
29
-
30
- self.install_pre_commit_hook
31
- end
32
-
33
- def install(entry)
34
- if entry.repo.exists?
35
- check_repo_validity(entry)
36
- fetch_repo(entry)
37
- else
38
- clone_repo(entry)
39
- end
40
- checkout_branch(entry)
41
- end
42
-
43
- # Repo operations
44
-
45
- def fetch_repo(entry)
46
- Console.log_substep("Working copy '#{entry.repo.path}' already exists, fetching instead...")
47
- raise MultiRepoException, "Could not fetch from remote #{entry.repo.remote('origin').url}" unless entry.repo.fetch
48
- end
49
-
50
- def clone_repo(entry)
51
- Console.log_substep("Cloning '#{entry.url} to #{entry.repo.path}'")
52
- raise MultiRepoException, "Could not clone remote #{entry.url}" unless entry.repo.clone(entry.url)
53
- end
54
-
55
- def checkout_branch(entry)
56
- branch = entry.repo.branch(entry.branch);
57
- raise MultiRepoException, "Could not checkout branch #{branch.name}" unless branch.checkout
58
- Console.log_substep("Checked out branch #{branch.name} -> origin/#{branch.name}")
59
- end
60
-
61
- # Validation
62
-
63
- def check_repo_validity(entry)
64
- unless entry.repo.remote("origin").url == entry.url
65
- raise MultiRepoException, "'#{entry.path}' origin URL (#{entry.repo.remote('origin').url}) does not match entry (#{entry.url})!"
66
- end
67
- end
68
- end
1
+ require "multirepo/utility/console"
2
+ require "multirepo/utility/utils"
3
+ require "multirepo/git/repo"
4
+
5
+ module MultiRepo
6
+ class InstallCommand < Command
7
+ self.command = "install"
8
+ self.summary = "Clones and checks out dependencies as defined in the .multirepo file, and installs git-multirepo's local hooks."
9
+
10
+ def run
11
+ validate_in_work_tree
12
+ ensure_multirepo_initialized
13
+
14
+ Console.log_step("Cloning dependencies and installing hook...")
15
+
16
+ install_internal
17
+
18
+ Console.log_step("Done!")
19
+ rescue MultiRepoException => e
20
+ Console.log_error(e.message)
21
+ end
22
+
23
+ def install_internal
24
+ config_entries = ConfigFile.load
25
+
26
+ Console.log_substep("Installing #{config_entries.count} dependencies...");
27
+
28
+ config_entries.each { |e| install(e) }
29
+
30
+ install_hooks
31
+ end
32
+
33
+ def install(entry)
34
+ if entry.repo.exists?
35
+ check_repo_validity(entry)
36
+ fetch_repo(entry)
37
+ else
38
+ clone_repo(entry)
39
+ end
40
+ checkout_branch(entry)
41
+ end
42
+
43
+ # Repo operations
44
+
45
+ def fetch_repo(entry)
46
+ Console.log_substep("Working copy '#{entry.repo.path}' already exists, fetching instead...")
47
+ raise MultiRepoException, "Could not fetch from remote #{entry.repo.remote('origin').url}" unless entry.repo.fetch
48
+ end
49
+
50
+ def clone_repo(entry)
51
+ Console.log_substep("Cloning '#{entry.url} to #{entry.repo.path}'")
52
+ raise MultiRepoException, "Could not clone remote #{entry.url}" unless entry.repo.clone(entry.url)
53
+ end
54
+
55
+ def checkout_branch(entry)
56
+ branch = entry.repo.branch(entry.branch);
57
+ raise MultiRepoException, "Could not checkout branch #{branch.name}" unless branch.checkout
58
+ Console.log_substep("Checked out branch #{branch.name} -> origin/#{branch.name}")
59
+ end
60
+
61
+ # Validation
62
+
63
+ def check_repo_validity(entry)
64
+ unless entry.repo.remote("origin").url == entry.url
65
+ raise MultiRepoException, "'#{entry.path}' origin URL (#{entry.repo.remote('origin').url}) does not match entry (#{entry.url})!"
66
+ end
67
+ end
68
+ end
69
69
  end