git-multirepo 1.0.0.beta21 → 1.0.0.beta24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +38 -38
- data/.rspec +2 -2
- data/Gemfile +4 -4
- data/Gemfile.lock +37 -37
- data/LICENSE +22 -22
- data/README.md +141 -139
- data/Rakefile +2 -2
- data/bin/multi +10 -10
- data/docs/git-multirepo-cheatsheet.docx +0 -0
- data/git-multirepo.gemspec +29 -29
- data/lib/commands.rb +11 -11
- data/lib/git-multirepo.rb +2 -2
- data/lib/info.rb +4 -4
- data/lib/multirepo/commands/add-command.rb +51 -51
- data/lib/multirepo/commands/branch-command.rb +52 -52
- data/lib/multirepo/commands/checkout-command.rb +119 -119
- data/lib/multirepo/commands/clone-command.rb +69 -69
- data/lib/multirepo/commands/command.rb +58 -50
- data/lib/multirepo/commands/fetch-command.rb +23 -23
- data/lib/multirepo/commands/init-command.rb +51 -51
- data/lib/multirepo/commands/install-command.rb +87 -87
- data/lib/multirepo/commands/open-command.rb +25 -25
- data/lib/multirepo/commands/remove-command.rb +48 -48
- data/lib/multirepo/commands/uninit-command.rb +20 -20
- data/lib/multirepo/commands/update-command.rb +47 -47
- data/lib/multirepo/config.rb +15 -12
- data/lib/multirepo/files/config-entry.rb +34 -34
- data/lib/multirepo/files/config-file.rb +37 -37
- data/lib/multirepo/files/lock-entry.rb +25 -25
- data/lib/multirepo/files/lock-file.rb +39 -39
- data/lib/multirepo/git/branch.rb +27 -27
- data/lib/multirepo/git/change.rb +10 -10
- data/lib/multirepo/git/git.rb +42 -38
- data/lib/multirepo/git/remote.rb +15 -15
- data/lib/multirepo/git/repo.rb +66 -66
- data/lib/multirepo/hooks/post-merge-hook.rb +19 -19
- data/lib/multirepo/hooks/pre-commit-hook.rb +25 -25
- data/lib/multirepo/hooks/prepare-commit-msg-hook.rb +27 -27
- data/lib/multirepo/multirepo-exception.rb +5 -5
- data/lib/multirepo/utility/console.rb +51 -51
- data/lib/multirepo/utility/runner.rb +32 -32
- data/lib/multirepo/utility/utils.rb +51 -51
- data/resources/post-merge +5 -5
- data/resources/pre-commit +5 -5
- data/resources/prepare-commit-msg +5 -5
- data/spec/integration/init_spec.rb +22 -22
- data/spec/spec_helper.rb +89 -89
- 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
|
data/lib/multirepo/git/branch.rb
CHANGED
@@ -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
|
data/lib/multirepo/git/change.rb
CHANGED
@@ -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
|
data/lib/multirepo/git/git.rb
CHANGED
@@ -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 = "
|
18
|
-
run(full_command, verbosity)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.run_in_working_dir(path, git_command, verbosity)
|
22
|
-
full_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
|
-
|
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
|
data/lib/multirepo/git/remote.rb
CHANGED
@@ -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
|
data/lib/multirepo/git/repo.rb
CHANGED
@@ -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
|