Class: MultiRepo::Repo
- Inherits:
-
Object
- Object
- MultiRepo::Repo
- Defined in:
- lib/multirepo/git/repo.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #branch(name) ⇒ Object
- #changes ⇒ Object
- #checkout(ref_name, force = false) ⇒ Object
- #clean? ⇒ Boolean
- #clone(url, options = nil) ⇒ Object
- #commit(id) ⇒ Object
- #current_branch ⇒ Object
- #current_commit ⇒ Object
- #current_revision ⇒ Object
-
#exists? ⇒ Boolean
Inspection.
-
#fetch ⇒ Object
Operations.
-
#head ⇒ Object
Current.
- #head_born? ⇒ Boolean
-
#initialize(path) ⇒ Repo
constructor
A new instance of Repo.
- #local_branches ⇒ Object
-
#ref(name) ⇒ Object
Factory methods.
- #remote(name) ⇒ Object
- #remote_branches ⇒ Object
Constructor Details
#initialize(path) ⇒ Repo
Returns a new instance of Repo.
11 12 13 14 |
# File 'lib/multirepo/git/repo.rb', line 11 def initialize(path) @path = path @basename = Pathname.new(path).basename.to_s end |
Instance Attribute Details
#basename ⇒ Object
Returns the value of attribute basename.
9 10 11 |
# File 'lib/multirepo/git/repo.rb', line 9 def basename @basename end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/multirepo/git/repo.rb', line 8 def path @path end |
Instance Method Details
#branch(name) ⇒ Object
104 105 106 |
# File 'lib/multirepo/git/repo.rb', line 104 def branch(name) Branch.new(self, name) end |
#changes ⇒ Object
44 45 46 47 48 |
# File 'lib/multirepo/git/repo.rb', line 44 def changes output = GitRunner.run(@path, "status --porcelain", Verbosity::OUTPUT_NEVER) lines = output.split("\n").each(&:strip).delete_if{ |f| f == "" } lines.map { |l| Change.new(l) } end |
#checkout(ref_name, force = false) ⇒ Object
73 74 75 76 77 |
# File 'lib/multirepo/git/repo.rb', line 73 def checkout(ref_name, force = false) forceFlag = force ? " -f" : "" GitRunner.run(@path, "checkout#{forceFlag} #{ref_name}", Verbosity::OUTPUT_ON_ERROR) GitRunner.last_command_succeeded end |
#clean? ⇒ Boolean
32 33 34 |
# File 'lib/multirepo/git/repo.rb', line 32 def clean? changes.count == 0 end |
#clone(url, options = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/multirepo/git/repo.rb', line 57 def clone(url, = nil) = {} unless branch = [:branch] command = "clone #{url} #{@path}" command << " -q" if [:quiet] || false command << " -b #{branch}" if branch command << " --recurse-submodules" command << " --shallow-submodules" if [:shallow] || false command << " --depth 1" if [:shallow] || false GitRunner.run_as_system(".", command) GitRunner.last_command_succeeded end |
#commit(id) ⇒ Object
112 113 114 |
# File 'lib/multirepo/git/repo.rb', line 112 def commit(id) Commit.new(self, id) end |
#current_branch ⇒ Object
91 92 93 94 95 96 |
# File 'lib/multirepo/git/repo.rb', line 91 def current_branch return nil unless exists? && head_born? name = GitRunner.run(@path, "rev-parse --abbrev-ref HEAD", Verbosity::OUTPUT_NEVER).strip return nil if name == "HEAD" # Code assumes that current_branch will be nil when we're in floating HEAD Branch.new(self, name) end |
#current_commit ⇒ Object
86 87 88 89 |
# File 'lib/multirepo/git/repo.rb', line 86 def current_commit return nil unless exists? && head_born? Commit.new(self, head.commit_id) end |
#current_revision ⇒ Object
28 29 30 |
# File 'lib/multirepo/git/repo.rb', line 28 def current_revision (current_branch || current_commit).name end |
#exists? ⇒ Boolean
Inspection
18 19 20 21 |
# File 'lib/multirepo/git/repo.rb', line 18 def exists? return false unless Dir.exist?("#{@path}/.git") return GitRunner.run(@path, "rev-parse --is-inside-work-tree", Verbosity::OUTPUT_NEVER).strip == "true" end |
#fetch ⇒ Object
Operations
52 53 54 55 |
# File 'lib/multirepo/git/repo.rb', line 52 def fetch GitRunner.run_as_system(@path, "fetch --prune") GitRunner.last_command_succeeded end |
#head ⇒ Object
Current
81 82 83 84 |
# File 'lib/multirepo/git/repo.rb', line 81 def head return nil unless exists? && head_born? Ref.new(self, "HEAD") end |
#head_born? ⇒ Boolean
23 24 25 26 |
# File 'lib/multirepo/git/repo.rb', line 23 def head_born? result = GitRunner.run(@path, "rev-parse HEAD --", Verbosity::OUTPUT_NEVER).strip return !result.start_with?("fatal: bad revision") end |
#local_branches ⇒ Object
36 37 38 |
# File 'lib/multirepo/git/repo.rb', line 36 def local_branches branches_by_removing_prefix(%r{^refs/heads/}) end |
#ref(name) ⇒ Object
Factory methods
100 101 102 |
# File 'lib/multirepo/git/repo.rb', line 100 def ref(name) Ref.new(self, name) end |
#remote(name) ⇒ Object
108 109 110 |
# File 'lib/multirepo/git/repo.rb', line 108 def remote(name) Remote.new(self, name) end |
#remote_branches ⇒ Object
40 41 42 |
# File 'lib/multirepo/git/repo.rb', line 40 def remote_branches branches_by_removing_prefix(%r{^refs/remotes/}) end |