Class: Cp8Cli::Branch

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Branch

Returns a new instance of Branch.



14
15
16
# File 'lib/cp8_cli/branch.rb', line 14

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/cp8_cli/branch.rb', line 12

def name
  @name
end

Class Method Details

.currentObject



18
19
20
# File 'lib/cp8_cli/branch.rb', line 18

def self.current
  new Command.read("git rev-parse --abbrev-ref HEAD")
end

.suggestionObject



22
23
24
# File 'lib/cp8_cli/branch.rb', line 22

def self.suggestion
  new("suggestion-#{SecureRandom.hex(8)}")
end

Instance Method Details

#checkoutObject



26
27
28
# File 'lib/cp8_cli/branch.rb', line 26

def checkout
  Command.run "git checkout #{name} >/dev/null 2>&1 || git checkout -b #{name}", title: "Checking out new branch"
end

#open_ciObject



38
39
40
# File 'lib/cp8_cli/branch.rb', line 38

def open_ci
  Ci.new(branch_name: name, repo: repo).open
end

#open_prObject



34
35
36
# File 'lib/cp8_cli/branch.rb', line 34

def open_pr
  pull_request.open
end

#pushObject



30
31
32
# File 'lib/cp8_cli/branch.rb', line 30

def push
  Command.run "git push origin #{name} -u", title: "Pushing to origin"
end

#resetObject



42
43
44
45
46
47
48
# File 'lib/cp8_cli/branch.rb', line 42

def reset
  if dirty?
    Command.error "Dirty working directory, not resetting."
  else
    Command.run "git reset --hard origin/#{name}", title: "Resetting branch"
  end
end

#to_sObject



50
51
52
# File 'lib/cp8_cli/branch.rb', line 50

def to_s
  name
end