Class: GitProc::GitBranch
- Inherits:
-
Object
- Object
- GitProc::GitBranch
- Includes:
- Comparable
- Defined in:
- lib/git-process/git_branch.rb
Overview
A Git Branch
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
the name of the branch.
Instance Method Summary collapse
-
#<=>(other) ⇒ int?
Implements Comparable based on the branch name.
- #checkout_to_new(new_branch, opts = {}) ⇒ Object
- #contains_all_of(branch_name) ⇒ Object
-
#current? ⇒ Boolean
Is this the current branch?.
-
#delete!(force = false) ⇒ String
Delete this branch.
-
#initialize(name, current, lib) ⇒ GitBranch
constructor
A new instance of GitBranch.
-
#is_ahead_of(base_branch_name) ⇒ Boolean
Does this branch contain every commit in base_branch_name as well as at least one more?.
-
#local? ⇒ Boolean
Does this represent a local branch?.
-
#logger ⇒ GitLogger
The logger to use.
-
#remote? ⇒ Boolean
Does this represent a remote branch?.
- #rename(new_name) ⇒ Object
-
#sha ⇒ String
The SHA-1 of the tip of this branch.
-
#to_s ⇒ String
The name of the branch.
- #upstream(upstream_name) ⇒ Object
Constructor Details
#initialize(name, current, lib) ⇒ GitBranch
instead of passing in current, detect it dynamically (e.g., look at HEAD)
Returns a new instance of GitBranch.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/git-process/git_branch.rb', line 32 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 ⇒ String (readonly)
the name of the branch
20 21 22 |
# File 'lib/git-process/git_branch.rb', line 20 def name @name end |
Instance Method Details
#<=>(other) ⇒ int?
Implements Comparable based on the branch name
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/git-process/git_branch.rb', line 87 def <=>(other) if other.nil? return nil elsif other.is_a? String return self.name <=> other elsif other.respond_to? :name return self.name <=> other.name else return nil end end |
#checkout_to_new(new_branch, opts = {}) ⇒ Object
138 139 140 |
# File 'lib/git-process/git_branch.rb', line 138 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
133 134 135 |
# File 'lib/git-process/git_branch.rb', line 133 def contains_all_of(branch_name) @lib.rev_list(@name, branch_name, :oneline => true, :num_revs => 1) == '' end |
#current? ⇒ Boolean
Returns is this the current branch?.
46 47 48 |
# File 'lib/git-process/git_branch.rb', line 46 def current? @current end |
#delete!(force = false) ⇒ String
Delete this branch
114 115 116 117 118 119 120 |
# File 'lib/git-process/git_branch.rb', line 114 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) ⇒ Boolean
Returns does this branch contain every commit in base_branch_name as well as at least one more?.
102 103 104 105 |
# File 'lib/git-process/git_branch.rb', line 102 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
Returns does this represent a local branch?.
58 59 60 |
# File 'lib/git-process/git_branch.rb', line 58 def local? !@remote end |
#logger ⇒ GitLogger
Returns the logger to use.
70 71 72 |
# File 'lib/git-process/git_branch.rb', line 70 def logger @lib.logger end |
#remote? ⇒ Boolean
Returns does this represent a remote branch?.
52 53 54 |
# File 'lib/git-process/git_branch.rb', line 52 def remote? @remote end |
#rename(new_name) ⇒ Object
123 124 125 |
# File 'lib/git-process/git_branch.rb', line 123 def rename(new_name) @lib.branch(@name, :rename => new_name) end |
#sha ⇒ String
Returns the SHA-1 of the tip of this branch.
76 77 78 |
# File 'lib/git-process/git_branch.rb', line 76 def sha @lib.sha(name) end |
#to_s ⇒ String
Returns the name of the branch.
64 65 66 |
# File 'lib/git-process/git_branch.rb', line 64 def to_s name end |
#upstream(upstream_name) ⇒ Object
128 129 130 |
# File 'lib/git-process/git_branch.rb', line 128 def upstream(upstream_name) @lib.branch(@name, :upstream => upstream_name) end |