Class: GitCleanup::Branch
- Inherits:
-
Object
- Object
- GitCleanup::Branch
- Includes:
- Comparable
- Defined in:
- lib/git-cleanup/branch.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #commit ⇒ Object
- #commits(ref) ⇒ Object
- #delete(local_branches = nil) ⇒ Object
- #diff(ref) ⇒ Object
-
#initialize(repo, ref) ⇒ Branch
constructor
A new instance of Branch.
- #to_s ⇒ Object
Constructor Details
#initialize(repo, ref) ⇒ Branch
Returns a new instance of Branch.
11 12 13 14 15 |
# File 'lib/git-cleanup/branch.rb', line 11 def initialize(repo, ref) @repo = repo @ref = ref @remote, @name = ref.name.split('/', 2) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/git-cleanup/branch.rb', line 9 def name @name end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
9 10 11 |
# File 'lib/git-cleanup/branch.rb', line 9 def ref @ref end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
9 10 11 |
# File 'lib/git-cleanup/branch.rb', line 9 def remote @remote end |
Class Method Details
.remote(repo) ⇒ Object
5 6 7 |
# File 'lib/git-cleanup/branch.rb', line 5 def self.remote(repo) repo.remotes.map { |r| new(repo, r) } end |
Instance Method Details
#<=>(other) ⇒ Object
47 48 49 |
# File 'lib/git-cleanup/branch.rb', line 47 def <=>(other) commit.committed_date <=> other.commit.committed_date end |
#commit ⇒ Object
29 30 31 |
# File 'lib/git-cleanup/branch.rb', line 29 def commit @ref.commit end |
#commits(ref) ⇒ Object
25 26 27 |
# File 'lib/git-cleanup/branch.rb', line 25 def commits(ref) @repo.git.native(:log, {}, "#{ref.commit.sha}..#{@ref.commit.sha}") end |
#delete(local_branches = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/git-cleanup/branch.rb', line 33 def delete(local_branches = nil) Formatador.display('[red]Deleting...[/]') @repo.git.native(:push, {}, @remote, ":#{@name}") Formatador.display_line('[red]done[/]') if local_branches && local_branches.include?(name) Helper.boolean "There is also a local branch called #{name}. Would you like to delete that too?" do Formatador.display('[red]Deleting...[/]') @repo.git.native(:branch, {}, '-d', name) Formatador.display_line('[red]done[/]') end end end |
#diff(ref) ⇒ Object
21 22 23 |
# File 'lib/git-cleanup/branch.rb', line 21 def diff(ref) @repo.git.native(:diff, {}, "#{ref.commit.sha}...#{@ref.commit.sha}") end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/git-cleanup/branch.rb', line 17 def to_s "#{remote}/#{name}" end |