Class: Gitt::Commands::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/gitt/commands/branch.rb

Overview

A Git branch command wrapper.

Instance Method Summary collapse

Constructor Details

#initialize(shell: SHELL) ⇒ Branch

Returns a new instance of Branch.



11
12
13
# File 'lib/gitt/commands/branch.rb', line 11

def initialize shell: SHELL
  @shell = shell
end

Instance Method Details

#callObject



22
# File 'lib/gitt/commands/branch.rb', line 22

def call(*) = shell.call("branch", *)

#default(fallback = "main") ⇒ Object



15
16
17
18
19
20
# File 'lib/gitt/commands/branch.rb', line 15

def default fallback = "main"
  shell.call("config", "init.defaultBranch")
       .fmap(&:chomp)
       .fmap { |name| name.empty? ? fallback : name }
       .or(Success(fallback))
end

#nameObject



24
# File 'lib/gitt/commands/branch.rb', line 24

def name = shell.call("rev-parse", "--abbrev-ref", "HEAD").fmap(&:chomp)