git-multirepo 1.0.0.beta21 → 1.0.0.beta24

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 (49) 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 +141 -139
  8. data/Rakefile +2 -2
  9. data/bin/multi +10 -10
  10. data/docs/git-multirepo-cheatsheet.docx +0 -0
  11. data/git-multirepo.gemspec +29 -29
  12. data/lib/commands.rb +11 -11
  13. data/lib/git-multirepo.rb +2 -2
  14. data/lib/info.rb +4 -4
  15. data/lib/multirepo/commands/add-command.rb +51 -51
  16. data/lib/multirepo/commands/branch-command.rb +52 -52
  17. data/lib/multirepo/commands/checkout-command.rb +119 -119
  18. data/lib/multirepo/commands/clone-command.rb +69 -69
  19. data/lib/multirepo/commands/command.rb +58 -50
  20. data/lib/multirepo/commands/fetch-command.rb +23 -23
  21. data/lib/multirepo/commands/init-command.rb +51 -51
  22. data/lib/multirepo/commands/install-command.rb +87 -87
  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 +20 -20
  26. data/lib/multirepo/commands/update-command.rb +47 -47
  27. data/lib/multirepo/config.rb +15 -12
  28. data/lib/multirepo/files/config-entry.rb +34 -34
  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 -39
  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 +42 -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 +19 -19
  38. data/lib/multirepo/hooks/pre-commit-hook.rb +25 -25
  39. data/lib/multirepo/hooks/prepare-commit-msg-hook.rb +27 -27
  40. data/lib/multirepo/multirepo-exception.rb +5 -5
  41. data/lib/multirepo/utility/console.rb +51 -51
  42. data/lib/multirepo/utility/runner.rb +32 -32
  43. data/lib/multirepo/utility/utils.rb +51 -51
  44. data/resources/post-merge +5 -5
  45. data/resources/pre-commit +5 -5
  46. data/resources/prepare-commit-msg +5 -5
  47. data/spec/integration/init_spec.rb +22 -22
  48. data/spec/spec_helper.rb +89 -89
  49. metadata +4 -3
@@ -1,26 +1,26 @@
1
- require "multirepo/utility/console"
2
- require "multirepo/git/repo"
3
-
4
- module MultiRepo
5
- class LockEntry
6
- attr_accessor :config_entry
7
- attr_accessor :name
8
- attr_accessor :id
9
- attr_accessor :head
10
- attr_accessor :branch
11
-
12
- def encode_with(coder)
13
- coder["name"] = @name
14
- coder["id"] = @id
15
- coder["head"] = @head
16
- coder["branch"] = @branch
17
- end
18
-
19
- def initialize(config_entry)
20
- @name = config_entry.repo.basename
21
- @id = config_entry.id
22
- @head = config_entry.repo.head_hash
23
- @branch = config_entry.repo.current_branch
24
- end
25
- end
1
+ require "multirepo/utility/console"
2
+ require "multirepo/git/repo"
3
+
4
+ module MultiRepo
5
+ class LockEntry
6
+ attr_accessor :config_entry
7
+ attr_accessor :name
8
+ attr_accessor :id
9
+ attr_accessor :head
10
+ attr_accessor :branch
11
+
12
+ def encode_with(coder)
13
+ coder["name"] = @name
14
+ coder["id"] = @id
15
+ coder["head"] = @head
16
+ coder["branch"] = @branch
17
+ end
18
+
19
+ def initialize(config_entry)
20
+ @name = config_entry.repo.basename
21
+ @id = config_entry.id
22
+ @head = config_entry.repo.head_hash
23
+ @branch = config_entry.repo.current_branch
24
+ end
25
+ end
26
26
  end
@@ -1,40 +1,40 @@
1
- require "pathname"
2
- require "psych"
3
-
4
- require "multirepo/git/git"
5
- require_relative "lock-entry"
6
- require_relative "config-file"
7
-
8
- module MultiRepo
9
- class LockFile
10
- FILE = Pathname.new(".multirepo.lock")
11
-
12
- def self.exists?
13
- FILE.exist?
14
- end
15
-
16
- def self.load
17
- Psych.load(FILE.read)
18
- end
19
-
20
- def self.update
21
- config_entries = ConfigFile.load
22
- lock_entries = config_entries.map { |c| LockEntry.new(c) }
23
-
24
- File.write(FILE.to_s, Psych.dump(lock_entries))
25
-
26
- Git.run_in_current_dir("add -A #{FILE.to_s}", Runner::Verbosity::OUTPUT_ON_ERROR)
27
- end
28
-
29
- def self.commit(message = nil)
30
- message = message || "[multirepo] Updated lock file"
31
- Git.run_in_current_dir("commit -m \"#{message}\" -o -- #{FILE.to_s}", Runner::Verbosity::OUTPUT_ON_ERROR)
32
- end
33
-
34
- def self.validate_components(line, components)
35
- unless components.count == 2
36
- raise MultiRepoException, "Wrong entry format in .multirepo.lock file: #{line}"
37
- end
38
- end
39
- end
1
+ require "pathname"
2
+ require "psych"
3
+
4
+ require "multirepo/git/git"
5
+ require_relative "lock-entry"
6
+ require_relative "config-file"
7
+
8
+ module MultiRepo
9
+ class LockFile
10
+ FILE = Pathname.new(".multirepo.lock")
11
+
12
+ def self.exists?
13
+ FILE.exist?
14
+ end
15
+
16
+ def self.load
17
+ Psych.load(FILE.read)
18
+ end
19
+
20
+ def self.update
21
+ config_entries = ConfigFile.load
22
+ lock_entries = config_entries.map { |c| LockEntry.new(c) }
23
+
24
+ File.write(FILE.to_s, Psych.dump(lock_entries))
25
+
26
+ Git.run_in_current_dir("add -A #{FILE.to_s}", Runner::Verbosity::OUTPUT_ON_ERROR)
27
+ end
28
+
29
+ def self.commit(message = nil)
30
+ message = message || "[multirepo] Updated lock file"
31
+ Git.run_in_current_dir("commit -m \"#{message}\" -o -- #{FILE.to_s}", Runner::Verbosity::OUTPUT_ON_ERROR)
32
+ end
33
+
34
+ def self.validate_components(line, components)
35
+ unless components.count == 2
36
+ raise MultiRepoException, "Wrong entry format in .multirepo.lock file: #{line}"
37
+ end
38
+ end
39
+ end
40
40
  end
@@ -1,28 +1,28 @@
1
- require_relative "git"
2
-
3
- module MultiRepo
4
- class Branch
5
- attr_accessor :name
6
-
7
- def initialize(repo, name)
8
- @repo = repo
9
- @name = name
10
- end
11
-
12
- def exists?
13
- lines = Git.run_in_working_dir(@repo.path, "branch", Runner::Verbosity::NEVER_OUTPUT).split("\n")
14
- branch_names = lines.map { |line| line.tr("* ", "")}
15
- branch_names.include?(@name)
16
- end
17
-
18
- def create(remote_tracking = false)
19
- Git.run_in_working_dir(@repo.path, "branch #{@name}", Runner::Verbosity::OUTPUT_ON_ERROR)
20
- Git.run_in_working_dir(@repo.path, "push -u origin #{name}", Runner::Verbosity::OUTPUT_ON_ERROR) if remote_tracking
21
- end
22
-
23
- def checkout
24
- Git.run_in_working_dir(@repo.path, "checkout #{@name}", Runner::Verbosity::OUTPUT_ON_ERROR)
25
- Git.last_command_succeeded
26
- end
27
- end
1
+ require_relative "git"
2
+
3
+ module MultiRepo
4
+ class Branch
5
+ attr_accessor :name
6
+
7
+ def initialize(repo, name)
8
+ @repo = repo
9
+ @name = name
10
+ end
11
+
12
+ def exists?
13
+ lines = Git.run_in_working_dir(@repo.path, "branch", Runner::Verbosity::NEVER_OUTPUT).split("\n")
14
+ branch_names = lines.map { |line| line.tr("* ", "")}
15
+ branch_names.include?(@name)
16
+ end
17
+
18
+ def create(remote_tracking = false)
19
+ Git.run_in_working_dir(@repo.path, "branch #{@name}", Runner::Verbosity::OUTPUT_ON_ERROR)
20
+ Git.run_in_working_dir(@repo.path, "push -u origin #{name}", Runner::Verbosity::OUTPUT_ON_ERROR) if remote_tracking
21
+ end
22
+
23
+ def checkout
24
+ Git.run_in_working_dir(@repo.path, "checkout #{@name}", Runner::Verbosity::OUTPUT_ON_ERROR)
25
+ Git.last_command_succeeded
26
+ end
27
+ end
28
28
  end
@@ -1,11 +1,11 @@
1
- module MultiRepo
2
- class Change
3
- attr_accessor :status
4
- attr_accessor :path
5
-
6
- def initialize(line)
7
- @status = line[0...2].strip
8
- @path = line[3..-1]
9
- end
10
- end
1
+ module MultiRepo
2
+ class Change
3
+ attr_accessor :status
4
+ attr_accessor :path
5
+
6
+ def initialize(line)
7
+ @status = line[0...2].strip
8
+ @path = line[3..-1]
9
+ end
10
+ end
11
11
  end
@@ -1,39 +1,43 @@
1
- require "multirepo/utility/runner"
2
- require "multirepo/git/git"
3
- require "multirepo/config"
4
-
5
- module MultiRepo
6
- class Git
7
- class << self
8
- attr_accessor :last_command_succeeded
9
- end
10
-
11
- def self.is_inside_git_repo(path)
12
- return false unless Dir.exist?("#{path}/.git")
13
- return Git.run_in_working_dir(path, "rev-parse --is-inside-work-tree", Runner::Verbosity::NEVER_OUTPUT).strip == "true"
14
- end
15
-
16
- def self.run_in_current_dir(git_command, verbosity)
17
- full_command = "git #{git_command}"
18
- run(full_command, verbosity)
19
- end
20
-
21
- def self.run_in_working_dir(path, git_command, verbosity)
22
- full_command = "git -C \"#{path}\" #{git_command}";
23
-
24
- # True fix for the -C flag issue in pre-commit hook where the status command would
25
- # fail to provide correct results if a pathspec was provided when performing a commit.
26
- # http://thread.gmane.org/gmane.comp.version-control.git/263319/focus=263323
27
- full_command = "sh -c 'unset $(git rev-parse --local-env-vars); #{full_command};'" if Config.instance.running_git_hook
28
-
29
- run(full_command, verbosity)
30
- end
31
-
32
- def self.run(full_command, verbosity)
33
- Console.log_info(full_command) if Config.instance.verbose
34
- result = Runner.run(full_command, verbosity)
35
- @last_command_succeeded = Runner.last_command_succeeded
36
- return result
37
- end
38
- end
1
+ require "multirepo/utility/runner"
2
+ require "multirepo/git/git"
3
+ require "multirepo/config"
4
+
5
+ module MultiRepo
6
+ class Git
7
+ class << self
8
+ attr_accessor :last_command_succeeded
9
+ end
10
+
11
+ def self.is_inside_git_repo(path)
12
+ return false unless Dir.exist?("#{path}/.git")
13
+ return Git.run_in_working_dir(path, "rev-parse --is-inside-work-tree", Runner::Verbosity::NEVER_OUTPUT).strip == "true"
14
+ end
15
+
16
+ def self.run_in_current_dir(git_command, verbosity)
17
+ full_command = "#{git_executable} #{git_command}"
18
+ run(full_command, verbosity)
19
+ end
20
+
21
+ def self.run_in_working_dir(path, git_command, verbosity)
22
+ full_command = "#{git_executable} -C \"#{path}\" #{git_command}";
23
+
24
+ # True fix for the -C flag issue in pre-commit hook where the status command would
25
+ # fail to provide correct results if a pathspec was provided when performing a commit.
26
+ # http://thread.gmane.org/gmane.comp.version-control.git/263319/focus=263323
27
+ full_command = "sh -c 'unset $(git rev-parse --local-env-vars); #{full_command};'" if Config.instance.running_git_hook
28
+
29
+ run(full_command, verbosity)
30
+ end
31
+
32
+ def self.run(full_command, verbosity)
33
+ Console.log_info(full_command) if Config.instance.verbose
34
+ result = Runner.run(full_command, verbosity)
35
+ @last_command_succeeded = Runner.last_command_succeeded
36
+ return result
37
+ end
38
+
39
+ def self.git_executable
40
+ Config.instance.git_executable || "git"
41
+ end
42
+ end
39
43
  end
@@ -1,16 +1,16 @@
1
- require_relative "git"
2
-
3
- module MultiRepo
4
- class Remote
5
- attr_accessor :name
6
-
7
- def initialize(repo, name)
8
- @repo = repo
9
- @name = name
10
- end
11
-
12
- def url
13
- Git.run_in_working_dir(@repo.path, "config --get remote.#{@name}.url", Runner::Verbosity::NEVER_OUTPUT).strip
14
- end
15
- end
1
+ require_relative "git"
2
+
3
+ module MultiRepo
4
+ class Remote
5
+ attr_accessor :name
6
+
7
+ def initialize(repo, name)
8
+ @repo = repo
9
+ @name = name
10
+ end
11
+
12
+ def url
13
+ Git.run_in_working_dir(@repo.path, "config --get remote.#{@name}.url", Runner::Verbosity::NEVER_OUTPUT).strip
14
+ end
15
+ end
16
16
  end
@@ -1,67 +1,67 @@
1
- require_relative "branch"
2
- require_relative "remote"
3
- require_relative "change"
4
-
5
- module MultiRepo
6
- class Repo
7
- attr_accessor :path
8
- attr_accessor :basename
9
-
10
- def initialize(path)
11
- @path = path
12
- @basename = Pathname.new(path).basename.to_s
13
- end
14
-
15
- # Inspection
16
-
17
- def exists?
18
- Git.is_inside_git_repo(@path)
19
- end
20
-
21
- def current_branch
22
- branch = Git.run_in_working_dir(@path, "rev-parse --abbrev-ref HEAD", Runner::Verbosity::NEVER_OUTPUT).strip
23
- branch != "HEAD" ? branch : nil
24
- end
25
-
26
- def head_hash
27
- Git.run_in_working_dir(@path, "rev-parse HEAD", Runner::Verbosity::NEVER_OUTPUT).strip
28
- end
29
-
30
- def changes
31
- output = Git.run_in_working_dir(@path, "status --porcelain", Runner::Verbosity::NEVER_OUTPUT)
32
- lines = output.split("\n").each{ |f| f.strip }.delete_if{ |f| f == "" }
33
- lines.map { |l| Change.new(l) }
34
- end
35
-
36
- def is_clean?
37
- return changes.count == 0
38
- end
39
-
40
- # Operations
41
-
42
- def fetch
43
- Git.run_in_working_dir(@path, "fetch --progress", Runner::Verbosity::ALWAYS_OUTPUT)
44
- Runner.last_command_succeeded
45
- end
46
-
47
- def clone(url)
48
- Git.run_in_current_dir("clone #{url} #{@path} --progress", Runner::Verbosity::ALWAYS_OUTPUT)
49
- Runner.last_command_succeeded
50
- end
51
-
52
- def checkout(ref)
53
- Git.run_in_working_dir(@path, "checkout #{ref}", Runner::Verbosity::OUTPUT_ON_ERROR)
54
- Runner.last_command_succeeded
55
- end
56
-
57
- # Remotes and branches
58
-
59
- def branch(name)
60
- Branch.new(self, name)
61
- end
62
-
63
- def remote(name)
64
- Remote.new(self, name)
65
- end
66
- end
1
+ require_relative "branch"
2
+ require_relative "remote"
3
+ require_relative "change"
4
+
5
+ module MultiRepo
6
+ class Repo
7
+ attr_accessor :path
8
+ attr_accessor :basename
9
+
10
+ def initialize(path)
11
+ @path = path
12
+ @basename = Pathname.new(path).basename.to_s
13
+ end
14
+
15
+ # Inspection
16
+
17
+ def exists?
18
+ Git.is_inside_git_repo(@path)
19
+ end
20
+
21
+ def current_branch
22
+ branch = Git.run_in_working_dir(@path, "rev-parse --abbrev-ref HEAD", Runner::Verbosity::NEVER_OUTPUT).strip
23
+ branch != "HEAD" ? branch : nil
24
+ end
25
+
26
+ def head_hash
27
+ Git.run_in_working_dir(@path, "rev-parse HEAD", Runner::Verbosity::NEVER_OUTPUT).strip
28
+ end
29
+
30
+ def changes
31
+ output = Git.run_in_working_dir(@path, "status --porcelain", Runner::Verbosity::NEVER_OUTPUT)
32
+ lines = output.split("\n").each{ |f| f.strip }.delete_if{ |f| f == "" }
33
+ lines.map { |l| Change.new(l) }
34
+ end
35
+
36
+ def is_clean?
37
+ return changes.count == 0
38
+ end
39
+
40
+ # Operations
41
+
42
+ def fetch
43
+ Git.run_in_working_dir(@path, "fetch --progress", Runner::Verbosity::ALWAYS_OUTPUT)
44
+ Runner.last_command_succeeded
45
+ end
46
+
47
+ def clone(url)
48
+ Git.run_in_current_dir("clone #{url} #{@path} --progress", Runner::Verbosity::ALWAYS_OUTPUT)
49
+ Runner.last_command_succeeded
50
+ end
51
+
52
+ def checkout(ref)
53
+ Git.run_in_working_dir(@path, "checkout #{ref}", Runner::Verbosity::OUTPUT_ON_ERROR)
54
+ Runner.last_command_succeeded
55
+ end
56
+
57
+ # Remotes and branches
58
+
59
+ def branch(name)
60
+ Branch.new(self, name)
61
+ end
62
+
63
+ def remote(name)
64
+ Remote.new(self, name)
65
+ end
66
+ end
67
67
  end