git-multirepo 1.0.0.beta49 → 1.0.0.beta50
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.meta +2 -2
- data/.rspec +2 -2
- data/.rubocop.yml +79 -79
- data/CHANGELOG.md +29 -25
- data/Gemfile +4 -4
- data/Gemfile.lock +42 -42
- data/LICENSE +22 -22
- data/README.md +154 -154
- data/Rakefile +1 -1
- data/bin/multi +11 -11
- data/docs/bug-repros/91565510-repro.sh +20 -20
- data/git-multirepo.gemspec +31 -31
- data/lib/git-multirepo.rb +3 -3
- data/lib/multirepo/commands/add-command.rb +51 -51
- data/lib/multirepo/commands/branch-command.rb +82 -82
- data/lib/multirepo/commands/checkout-command.rb +120 -120
- data/lib/multirepo/commands/clone-command.rb +68 -68
- data/lib/multirepo/commands/command.rb +90 -90
- data/lib/multirepo/commands/commands.rb +15 -0
- data/lib/multirepo/commands/do-command.rb +103 -103
- data/lib/multirepo/commands/graph-command.rb +43 -43
- data/lib/multirepo/commands/init-command.rb +121 -121
- data/lib/multirepo/commands/inspect-command.rb +39 -39
- data/lib/multirepo/commands/install-command.rb +153 -153
- data/lib/multirepo/commands/merge-command.rb +249 -225
- data/lib/multirepo/commands/open-command.rb +57 -57
- data/lib/multirepo/commands/remove-command.rb +48 -48
- data/lib/multirepo/commands/uninit-command.rb +18 -18
- data/lib/multirepo/commands/update-command.rb +106 -94
- data/lib/multirepo/config.rb +16 -16
- data/lib/multirepo/files/config-entry.rb +39 -39
- data/lib/multirepo/files/config-file.rb +46 -46
- data/lib/multirepo/files/lock-entry.rb +29 -29
- data/lib/multirepo/files/lock-file.rb +56 -56
- data/lib/multirepo/files/meta-file.rb +41 -41
- data/lib/multirepo/files/tracking-file.rb +9 -9
- data/lib/multirepo/files/tracking-files.rb +47 -47
- data/lib/multirepo/git/branch.rb +32 -32
- data/lib/multirepo/git/change.rb +11 -11
- data/lib/multirepo/git/commit.rb +7 -7
- data/lib/multirepo/git/git-runner.rb +56 -56
- data/lib/multirepo/git/git.rb +10 -10
- data/lib/multirepo/git/ref.rb +38 -38
- data/lib/multirepo/git/remote.rb +17 -17
- data/lib/multirepo/git/repo.rb +124 -124
- data/lib/multirepo/hooks/post-commit-hook.rb +23 -23
- data/lib/multirepo/hooks/pre-commit-hook.rb +35 -35
- data/lib/{info.rb → multirepo/info.rb} +5 -5
- data/lib/multirepo/logic/dependency.rb +6 -6
- data/lib/multirepo/logic/merge-descriptor.rb +95 -95
- data/lib/multirepo/logic/node.rb +72 -72
- data/lib/multirepo/logic/performer.rb +55 -55
- data/lib/multirepo/logic/revision-selector.rb +35 -35
- data/lib/multirepo/multirepo-exception.rb +6 -6
- data/lib/multirepo/utility/console.rb +52 -52
- data/lib/multirepo/utility/popen-runner.rb +27 -27
- data/lib/multirepo/utility/system-runner.rb +14 -14
- data/lib/multirepo/utility/utils.rb +95 -95
- data/lib/multirepo/utility/verbosity.rb +6 -6
- data/resources/.gitconfig +2 -2
- data/resources/post-commit +6 -6
- data/resources/pre-commit +6 -6
- data/spec/integration/init_spec.rb +19 -19
- data/spec/spec_helper.rb +89 -89
- metadata +33 -33
- data/lib/commands.rb +0 -15
data/lib/multirepo/git/branch.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
require_relative "ref"
|
2
|
-
require_relative "git-runner"
|
3
|
-
|
4
|
-
module MultiRepo
|
5
|
-
class Branch < Ref
|
6
|
-
def exists?
|
7
|
-
lines = GitRunner.run(@repo.path, "branch", Verbosity::OUTPUT_NEVER).split("\n")
|
8
|
-
branch_names = lines.map { |line| line.tr("* ", "") }
|
9
|
-
branch_names.include?(@name)
|
10
|
-
end
|
11
|
-
|
12
|
-
def upstream_branch
|
13
|
-
output = GitRunner.run(@repo.path, "config --get branch.#{@name}.merge", Verbosity::OUTPUT_NEVER)
|
14
|
-
output.sub!("refs/heads/", "")
|
15
|
-
return nil if output == ""
|
16
|
-
Branch.new(@repo, "origin/#{output}")
|
17
|
-
end
|
18
|
-
|
19
|
-
def create
|
20
|
-
GitRunner.run(@repo.path, "branch #{@name}", Verbosity::OUTPUT_ON_ERROR)
|
21
|
-
end
|
22
|
-
|
23
|
-
def push
|
24
|
-
GitRunner.run(@repo.path, "push -u origin #{@name}", Verbosity::OUTPUT_ON_ERROR)
|
25
|
-
end
|
26
|
-
|
27
|
-
def checkout
|
28
|
-
GitRunner.run(@repo.path, "checkout #{@name}", Verbosity::OUTPUT_ON_ERROR)
|
29
|
-
GitRunner.last_command_succeeded
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
1
|
+
require_relative "ref"
|
2
|
+
require_relative "git-runner"
|
3
|
+
|
4
|
+
module MultiRepo
|
5
|
+
class Branch < Ref
|
6
|
+
def exists?
|
7
|
+
lines = GitRunner.run(@repo.path, "branch", Verbosity::OUTPUT_NEVER).split("\n")
|
8
|
+
branch_names = lines.map { |line| line.tr("* ", "") }
|
9
|
+
branch_names.include?(@name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def upstream_branch
|
13
|
+
output = GitRunner.run(@repo.path, "config --get branch.#{@name}.merge", Verbosity::OUTPUT_NEVER)
|
14
|
+
output.sub!("refs/heads/", "")
|
15
|
+
return nil if output == ""
|
16
|
+
Branch.new(@repo, "origin/#{output}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
GitRunner.run(@repo.path, "branch #{@name}", Verbosity::OUTPUT_ON_ERROR)
|
21
|
+
end
|
22
|
+
|
23
|
+
def push
|
24
|
+
GitRunner.run(@repo.path, "push -u origin #{@name}", Verbosity::OUTPUT_ON_ERROR)
|
25
|
+
end
|
26
|
+
|
27
|
+
def checkout
|
28
|
+
GitRunner.run(@repo.path, "checkout #{@name}", Verbosity::OUTPUT_ON_ERROR)
|
29
|
+
GitRunner.last_command_succeeded
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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
|
11
|
-
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
|
+
end
|
data/lib/multirepo/git/commit.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative "ref"
|
2
|
-
require_relative "git-runner"
|
3
|
-
|
4
|
-
module MultiRepo
|
5
|
-
class Commit < Ref
|
6
|
-
end
|
7
|
-
end
|
1
|
+
require_relative "ref"
|
2
|
+
require_relative "git-runner"
|
3
|
+
|
4
|
+
module MultiRepo
|
5
|
+
class Commit < Ref
|
6
|
+
end
|
7
|
+
end
|
@@ -1,56 +1,56 @@
|
|
1
|
-
require "multirepo/utility/verbosity"
|
2
|
-
require "multirepo/utility/popen-runner"
|
3
|
-
require "multirepo/utility/system-runner"
|
4
|
-
require "multirepo/config"
|
5
|
-
|
6
|
-
module MultiRepo
|
7
|
-
class GitRunner
|
8
|
-
class << self
|
9
|
-
attr_accessor :last_command_succeeded
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.run(path, git_command, verbosity)
|
13
|
-
command = build_command(path, git_command)
|
14
|
-
runner_popen(command, verbosity)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.run_as_system(path, git_command)
|
18
|
-
command = build_command(path, git_command)
|
19
|
-
runner_system(command)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.build_command(path, git_command)
|
23
|
-
if path == "."
|
24
|
-
# It is always better to skip -C when running git commands in the
|
25
|
-
# current directory (especially in hooks). Doing this prevents
|
26
|
-
# any future issues because we automatically fallback to non-"-C" for ".".
|
27
|
-
# Fixes bug: https://www.pivotaltracker.com/story/show/94505654
|
28
|
-
return "#{git_executable} #{git_command}"
|
29
|
-
end
|
30
|
-
|
31
|
-
full_command = "#{git_executable} -C \"#{path}\" #{git_command}"
|
32
|
-
if Config.instance.running_git_hook
|
33
|
-
# True fix for the -C flag issue in pre-commit hook where the status command would
|
34
|
-
# fail to provide correct results if a pathspec was provided when performing a commit.
|
35
|
-
# http://thread.gmane.org/gmane.comp.version-control.git/263319/focus=263323
|
36
|
-
full_command = "sh -c 'unset $(git rev-parse --local-env-vars); #{full_command};'"
|
37
|
-
end
|
38
|
-
|
39
|
-
return full_command
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.runner_popen(full_command, verbosity)
|
43
|
-
result, @last_command_succeeded = PopenRunner.run(full_command, verbosity)
|
44
|
-
return result
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.runner_system(full_command)
|
48
|
-
result, @last_command_succeeded = SystemRunner.run(full_command)
|
49
|
-
return result
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.git_executable
|
53
|
-
Config.instance.git_executable || "git"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
1
|
+
require "multirepo/utility/verbosity"
|
2
|
+
require "multirepo/utility/popen-runner"
|
3
|
+
require "multirepo/utility/system-runner"
|
4
|
+
require "multirepo/config"
|
5
|
+
|
6
|
+
module MultiRepo
|
7
|
+
class GitRunner
|
8
|
+
class << self
|
9
|
+
attr_accessor :last_command_succeeded
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run(path, git_command, verbosity)
|
13
|
+
command = build_command(path, git_command)
|
14
|
+
runner_popen(command, verbosity)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.run_as_system(path, git_command)
|
18
|
+
command = build_command(path, git_command)
|
19
|
+
runner_system(command)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.build_command(path, git_command)
|
23
|
+
if path == "."
|
24
|
+
# It is always better to skip -C when running git commands in the
|
25
|
+
# current directory (especially in hooks). Doing this prevents
|
26
|
+
# any future issues because we automatically fallback to non-"-C" for ".".
|
27
|
+
# Fixes bug: https://www.pivotaltracker.com/story/show/94505654
|
28
|
+
return "#{git_executable} #{git_command}"
|
29
|
+
end
|
30
|
+
|
31
|
+
full_command = "#{git_executable} -C \"#{path}\" #{git_command}"
|
32
|
+
if Config.instance.running_git_hook
|
33
|
+
# True fix for the -C flag issue in pre-commit hook where the status command would
|
34
|
+
# fail to provide correct results if a pathspec was provided when performing a commit.
|
35
|
+
# http://thread.gmane.org/gmane.comp.version-control.git/263319/focus=263323
|
36
|
+
full_command = "sh -c 'unset $(git rev-parse --local-env-vars); #{full_command};'"
|
37
|
+
end
|
38
|
+
|
39
|
+
return full_command
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.runner_popen(full_command, verbosity)
|
43
|
+
result, @last_command_succeeded = PopenRunner.run(full_command, verbosity)
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.runner_system(full_command)
|
48
|
+
result, @last_command_succeeded = SystemRunner.run(full_command)
|
49
|
+
return result
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.git_executable
|
53
|
+
Config.instance.git_executable || "git"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/multirepo/git/git.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require "multirepo/git/git-runner"
|
2
|
-
|
3
|
-
module MultiRepo
|
4
|
-
class Git
|
5
|
-
def self.valid_branch_name?(name)
|
6
|
-
GitRunner.run(".", "check-ref-format --branch \"#{name}\"", Verbosity::OUTPUT_NEVER)
|
7
|
-
GitRunner.last_command_succeeded
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
require "multirepo/git/git-runner"
|
2
|
+
|
3
|
+
module MultiRepo
|
4
|
+
class Git
|
5
|
+
def self.valid_branch_name?(name)
|
6
|
+
GitRunner.run(".", "check-ref-format --branch \"#{name}\"", Verbosity::OUTPUT_NEVER)
|
7
|
+
GitRunner.last_command_succeeded
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/multirepo/git/ref.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
require_relative "git-runner"
|
2
|
-
|
3
|
-
module MultiRepo
|
4
|
-
class Ref
|
5
|
-
attr_accessor :name
|
6
|
-
|
7
|
-
def initialize(repo, name)
|
8
|
-
@repo = repo
|
9
|
-
@name = name
|
10
|
-
end
|
11
|
-
|
12
|
-
def exists?
|
13
|
-
output = GitRunner.run(@repo.path, "rev-parse --verify --quiet #{@name}", Verbosity::OUTPUT_NEVER).strip
|
14
|
-
return output != ""
|
15
|
-
end
|
16
|
-
|
17
|
-
def commit_id
|
18
|
-
GitRunner.run(@repo.path, "rev-parse #{@name}", Verbosity::OUTPUT_NEVER).strip
|
19
|
-
end
|
20
|
-
|
21
|
-
def short_commit_id
|
22
|
-
GitRunner.run(@repo.path, "rev-parse --short #{@name}", Verbosity::OUTPUT_NEVER).strip
|
23
|
-
end
|
24
|
-
|
25
|
-
def merge_commit?
|
26
|
-
lines = GitRunner.run(@repo.path, "cat-file -p #{@name}", Verbosity::OUTPUT_NEVER).split("\n")
|
27
|
-
parents = lines.grep(/^parent /)
|
28
|
-
return parents.count > 1
|
29
|
-
end
|
30
|
-
|
31
|
-
def can_fast_forward_to?(ref)
|
32
|
-
# http://stackoverflow.com/a/2934062/167983
|
33
|
-
rev_parse_output = GitRunner.run(@repo.path, "rev-parse #{@name}", Verbosity::OUTPUT_NEVER)
|
34
|
-
merge_base_output = GitRunner.run(@repo.path, "merge-base \"#{rev_parse_output}\" \"#{ref.name}\"", Verbosity::OUTPUT_NEVER)
|
35
|
-
return merge_base_output == rev_parse_output
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
require_relative "git-runner"
|
2
|
+
|
3
|
+
module MultiRepo
|
4
|
+
class Ref
|
5
|
+
attr_accessor :name
|
6
|
+
|
7
|
+
def initialize(repo, name)
|
8
|
+
@repo = repo
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def exists?
|
13
|
+
output = GitRunner.run(@repo.path, "rev-parse --verify --quiet #{@name}", Verbosity::OUTPUT_NEVER).strip
|
14
|
+
return output != ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def commit_id
|
18
|
+
GitRunner.run(@repo.path, "rev-parse #{@name}", Verbosity::OUTPUT_NEVER).strip
|
19
|
+
end
|
20
|
+
|
21
|
+
def short_commit_id
|
22
|
+
GitRunner.run(@repo.path, "rev-parse --short #{@name}", Verbosity::OUTPUT_NEVER).strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def merge_commit?
|
26
|
+
lines = GitRunner.run(@repo.path, "cat-file -p #{@name}", Verbosity::OUTPUT_NEVER).split("\n")
|
27
|
+
parents = lines.grep(/^parent /)
|
28
|
+
return parents.count > 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def can_fast_forward_to?(ref)
|
32
|
+
# http://stackoverflow.com/a/2934062/167983
|
33
|
+
rev_parse_output = GitRunner.run(@repo.path, "rev-parse #{@name}", Verbosity::OUTPUT_NEVER)
|
34
|
+
merge_base_output = GitRunner.run(@repo.path, "merge-base \"#{rev_parse_output}\" \"#{ref.name}\"", Verbosity::OUTPUT_NEVER)
|
35
|
+
return merge_base_output == rev_parse_output
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/multirepo/git/remote.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require_relative "git-runner"
|
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
|
-
output = GitRunner.run(@repo.path, "config --get remote.#{@name}.url", Verbosity::OUTPUT_NEVER).strip
|
14
|
-
return output == "" ? nil : output
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require_relative "git-runner"
|
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
|
+
output = GitRunner.run(@repo.path, "config --get remote.#{@name}.url", Verbosity::OUTPUT_NEVER).strip
|
14
|
+
return output == "" ? nil : output
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/multirepo/git/repo.rb
CHANGED
@@ -1,124 +1,124 @@
|
|
1
|
-
require_relative "branch"
|
2
|
-
require_relative "remote"
|
3
|
-
require_relative "commit"
|
4
|
-
require_relative "change"
|
5
|
-
|
6
|
-
module MultiRepo
|
7
|
-
class Repo
|
8
|
-
attr_accessor :path
|
9
|
-
attr_accessor :basename
|
10
|
-
|
11
|
-
def initialize(path)
|
12
|
-
@path = path
|
13
|
-
@basename = Pathname.new(path).basename.to_s
|
14
|
-
end
|
15
|
-
|
16
|
-
# Inspection
|
17
|
-
|
18
|
-
def exists?
|
19
|
-
return false unless Dir.exist?("#{@path}/.git")
|
20
|
-
return GitRunner.run(@path, "rev-parse --is-inside-work-tree", Verbosity::OUTPUT_NEVER).strip == "true"
|
21
|
-
end
|
22
|
-
|
23
|
-
def head_born?
|
24
|
-
result = GitRunner.run(@path, "rev-parse HEAD --", Verbosity::OUTPUT_NEVER).strip
|
25
|
-
return !result.start_with?("fatal: bad revision")
|
26
|
-
end
|
27
|
-
|
28
|
-
def current_revision
|
29
|
-
(current_branch || current_commit).name
|
30
|
-
end
|
31
|
-
|
32
|
-
def clean?
|
33
|
-
changes.count == 0
|
34
|
-
end
|
35
|
-
|
36
|
-
def local_branches
|
37
|
-
branches_by_removing_prefix(%r{^refs/heads/})
|
38
|
-
end
|
39
|
-
|
40
|
-
def remote_branches
|
41
|
-
branches_by_removing_prefix(%r{^refs/remotes/})
|
42
|
-
end
|
43
|
-
|
44
|
-
def changes
|
45
|
-
output = GitRunner.run(@path, "status --porcelain", Verbosity::OUTPUT_NEVER)
|
46
|
-
lines = output.split("\n").each(&:strip).delete_if{ |f| f == "" }
|
47
|
-
lines.map { |l| Change.new(l) }
|
48
|
-
end
|
49
|
-
|
50
|
-
# Operations
|
51
|
-
|
52
|
-
def fetch
|
53
|
-
GitRunner.run_as_system(@path, "fetch --prune --progress")
|
54
|
-
GitRunner.last_command_succeeded
|
55
|
-
end
|
56
|
-
|
57
|
-
def clone(url, branch = nil)
|
58
|
-
if !branch.nil?
|
59
|
-
GitRunner.run_as_system(".", "clone #{url} -b #{branch} #{@path} --progress")
|
60
|
-
else
|
61
|
-
GitRunner.run_as_system(".", "clone #{url} #{@path} --progress")
|
62
|
-
end
|
63
|
-
GitRunner.last_command_succeeded
|
64
|
-
end
|
65
|
-
|
66
|
-
def checkout(ref_name)
|
67
|
-
GitRunner.run(@path, "checkout #{ref_name}", Verbosity::OUTPUT_ON_ERROR)
|
68
|
-
GitRunner.last_command_succeeded
|
69
|
-
end
|
70
|
-
|
71
|
-
# Current
|
72
|
-
|
73
|
-
def head
|
74
|
-
return nil unless exists? && head_born?
|
75
|
-
Ref.new(self, "HEAD")
|
76
|
-
end
|
77
|
-
|
78
|
-
def current_commit
|
79
|
-
return nil unless exists? && head_born?
|
80
|
-
Commit.new(self, head.commit_id)
|
81
|
-
end
|
82
|
-
|
83
|
-
def current_branch
|
84
|
-
return nil unless exists? && head_born?
|
85
|
-
name = GitRunner.run(@path, "rev-parse --abbrev-ref HEAD", Verbosity::OUTPUT_NEVER).strip
|
86
|
-
return nil if name == "HEAD" # Code assumes that current_branch will be nil when we're in floating HEAD
|
87
|
-
Branch.new(self, name)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Factory methods
|
91
|
-
|
92
|
-
def ref(name)
|
93
|
-
Ref.new(self, name)
|
94
|
-
end
|
95
|
-
|
96
|
-
def branch(name)
|
97
|
-
Branch.new(self, name)
|
98
|
-
end
|
99
|
-
|
100
|
-
def remote(name)
|
101
|
-
Remote.new(self, name)
|
102
|
-
end
|
103
|
-
|
104
|
-
def commit(id)
|
105
|
-
Commit.new(self, id)
|
106
|
-
end
|
107
|
-
|
108
|
-
# Private helper methods
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
def branches_by_removing_prefix(prefix_regex)
|
113
|
-
output = GitRunner.run(@path, "for-each-ref --format='%(refname)'", Verbosity::OUTPUT_NEVER)
|
114
|
-
all_refs = output.strip.split("\n")
|
115
|
-
|
116
|
-
# Remove surrounding quotes on Windows
|
117
|
-
all_refs = all_refs.map { |l| l.sub(/^\'/, "").sub(/\'$/, "") }
|
118
|
-
|
119
|
-
full_names = all_refs.select { |r| r =~ prefix_regex }
|
120
|
-
names = full_names.map{ |f| f.sub(prefix_regex, "") }.delete_if{ |n| n =~ /HEAD$/ }
|
121
|
-
names.map { |b| Branch.new(self, b) }
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
1
|
+
require_relative "branch"
|
2
|
+
require_relative "remote"
|
3
|
+
require_relative "commit"
|
4
|
+
require_relative "change"
|
5
|
+
|
6
|
+
module MultiRepo
|
7
|
+
class Repo
|
8
|
+
attr_accessor :path
|
9
|
+
attr_accessor :basename
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@path = path
|
13
|
+
@basename = Pathname.new(path).basename.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
# Inspection
|
17
|
+
|
18
|
+
def exists?
|
19
|
+
return false unless Dir.exist?("#{@path}/.git")
|
20
|
+
return GitRunner.run(@path, "rev-parse --is-inside-work-tree", Verbosity::OUTPUT_NEVER).strip == "true"
|
21
|
+
end
|
22
|
+
|
23
|
+
def head_born?
|
24
|
+
result = GitRunner.run(@path, "rev-parse HEAD --", Verbosity::OUTPUT_NEVER).strip
|
25
|
+
return !result.start_with?("fatal: bad revision")
|
26
|
+
end
|
27
|
+
|
28
|
+
def current_revision
|
29
|
+
(current_branch || current_commit).name
|
30
|
+
end
|
31
|
+
|
32
|
+
def clean?
|
33
|
+
changes.count == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
def local_branches
|
37
|
+
branches_by_removing_prefix(%r{^refs/heads/})
|
38
|
+
end
|
39
|
+
|
40
|
+
def remote_branches
|
41
|
+
branches_by_removing_prefix(%r{^refs/remotes/})
|
42
|
+
end
|
43
|
+
|
44
|
+
def changes
|
45
|
+
output = GitRunner.run(@path, "status --porcelain", Verbosity::OUTPUT_NEVER)
|
46
|
+
lines = output.split("\n").each(&:strip).delete_if{ |f| f == "" }
|
47
|
+
lines.map { |l| Change.new(l) }
|
48
|
+
end
|
49
|
+
|
50
|
+
# Operations
|
51
|
+
|
52
|
+
def fetch
|
53
|
+
GitRunner.run_as_system(@path, "fetch --prune --progress")
|
54
|
+
GitRunner.last_command_succeeded
|
55
|
+
end
|
56
|
+
|
57
|
+
def clone(url, branch = nil)
|
58
|
+
if !branch.nil?
|
59
|
+
GitRunner.run_as_system(".", "clone #{url} -b #{branch} #{@path} --progress")
|
60
|
+
else
|
61
|
+
GitRunner.run_as_system(".", "clone #{url} #{@path} --progress")
|
62
|
+
end
|
63
|
+
GitRunner.last_command_succeeded
|
64
|
+
end
|
65
|
+
|
66
|
+
def checkout(ref_name)
|
67
|
+
GitRunner.run(@path, "checkout #{ref_name}", Verbosity::OUTPUT_ON_ERROR)
|
68
|
+
GitRunner.last_command_succeeded
|
69
|
+
end
|
70
|
+
|
71
|
+
# Current
|
72
|
+
|
73
|
+
def head
|
74
|
+
return nil unless exists? && head_born?
|
75
|
+
Ref.new(self, "HEAD")
|
76
|
+
end
|
77
|
+
|
78
|
+
def current_commit
|
79
|
+
return nil unless exists? && head_born?
|
80
|
+
Commit.new(self, head.commit_id)
|
81
|
+
end
|
82
|
+
|
83
|
+
def current_branch
|
84
|
+
return nil unless exists? && head_born?
|
85
|
+
name = GitRunner.run(@path, "rev-parse --abbrev-ref HEAD", Verbosity::OUTPUT_NEVER).strip
|
86
|
+
return nil if name == "HEAD" # Code assumes that current_branch will be nil when we're in floating HEAD
|
87
|
+
Branch.new(self, name)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Factory methods
|
91
|
+
|
92
|
+
def ref(name)
|
93
|
+
Ref.new(self, name)
|
94
|
+
end
|
95
|
+
|
96
|
+
def branch(name)
|
97
|
+
Branch.new(self, name)
|
98
|
+
end
|
99
|
+
|
100
|
+
def remote(name)
|
101
|
+
Remote.new(self, name)
|
102
|
+
end
|
103
|
+
|
104
|
+
def commit(id)
|
105
|
+
Commit.new(self, id)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Private helper methods
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def branches_by_removing_prefix(prefix_regex)
|
113
|
+
output = GitRunner.run(@path, "for-each-ref --format='%(refname)'", Verbosity::OUTPUT_NEVER)
|
114
|
+
all_refs = output.strip.split("\n")
|
115
|
+
|
116
|
+
# Remove surrounding quotes on Windows
|
117
|
+
all_refs = all_refs.map { |l| l.sub(/^\'/, "").sub(/\'$/, "") }
|
118
|
+
|
119
|
+
full_names = all_refs.select { |r| r =~ prefix_regex }
|
120
|
+
names = full_names.map{ |f| f.sub(prefix_regex, "") }.delete_if{ |n| n =~ /HEAD$/ }
|
121
|
+
names.map { |b| Branch.new(self, b) }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|