Class: GitProc::GitBranch
- Inherits:
-
Object
- Object
- GitProc::GitBranch
- Includes:
- Comparable
- Defined in:
- lib/git-process/git_branch.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #checkout_to_new(new_branch, opts = {}) ⇒ Object
- #contains_all_of(branch_name) ⇒ Object
- #current? ⇒ Boolean
- #delete!(force = false) ⇒ Object
-
#initialize(name, current, lib) ⇒ GitBranch
constructor
A new instance of GitBranch.
- #is_ahead_of(base_branch_name) ⇒ Object
- #local? ⇒ Boolean
- #logger ⇒ Object
- #remote? ⇒ Boolean
- #rename(new_name) ⇒ Object
- #sha ⇒ Object
- #to_s ⇒ Object
- #upstream(upstream_name) ⇒ Object
Constructor Details
#initialize(name, current, lib) ⇒ GitBranch
Returns a new instance of GitBranch.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/git-process/git_branch.rb', line 21 def initialize(name, current, lib) if /^remotes\// =~ name @name = name[8..-1] @remote = true else @name = name @remote = false end @current = current @lib = lib end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/git-process/git_branch.rb', line 18 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
64 65 66 |
# File 'lib/git-process/git_branch.rb', line 64 def <=>(other) self.name <=> other.name end |
#checkout_to_new(new_branch, opts = {}) ⇒ Object
99 100 101 |
# File 'lib/git-process/git_branch.rb', line 99 def checkout_to_new(new_branch, opts = {}) @lib.checkout(new_branch, :new_branch => @name, :no_track => opts[:no_track]) end |
#contains_all_of(branch_name) ⇒ Object
94 95 96 |
# File 'lib/git-process/git_branch.rb', line 94 def contains_all_of(branch_name) @lib.rev_list(@name, branch_name, :oneline => true, :num_revs => 1) == '' end |
#current? ⇒ Boolean
34 35 36 |
# File 'lib/git-process/git_branch.rb', line 34 def current? @current end |
#delete!(force = false) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/git-process/git_branch.rb', line 75 def delete!(force = false) if local? @lib.branch(@name, :force => force, :delete => true) else @lib.push(Process.server_name, nil, nil, :delete => @name) end end |
#is_ahead_of(base_branch_name) ⇒ Object
69 70 71 72 |
# File 'lib/git-process/git_branch.rb', line 69 def is_ahead_of(base_branch_name) contains_all_of(base_branch_name) and (@lib.rev_list(base_branch_name, @name, :oneline => true, :num_revs => 1) != '') end |
#local? ⇒ Boolean
44 45 46 |
# File 'lib/git-process/git_branch.rb', line 44 def local? !@remote end |
#logger ⇒ Object
54 55 56 |
# File 'lib/git-process/git_branch.rb', line 54 def logger @lib.logger end |
#remote? ⇒ Boolean
39 40 41 |
# File 'lib/git-process/git_branch.rb', line 39 def remote? @remote end |
#rename(new_name) ⇒ Object
84 85 86 |
# File 'lib/git-process/git_branch.rb', line 84 def rename(new_name) @lib.branch(@name, :rename => new_name) end |
#sha ⇒ Object
59 60 61 |
# File 'lib/git-process/git_branch.rb', line 59 def sha @sha ||= @lib.sha(name) end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/git-process/git_branch.rb', line 49 def to_s name end |
#upstream(upstream_name) ⇒ Object
89 90 91 |
# File 'lib/git-process/git_branch.rb', line 89 def upstream(upstream_name) @lib.branch(@name, :upstream => upstream_name) end |