Class: HustleAndFlow::VersionControls::Git::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/hustle_and_flow/version_controls/git/branch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo:, branch:) ⇒ Branch



8
9
10
11
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 8

def initialize(repo:, branch:)
  self.repo   = repo
  self.branch = branch
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



5
6
7
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 5

def branch
  @branch
end

#repoObject

Returns the value of attribute repo.



5
6
7
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 5

def repo
  @repo
end

Instance Method Details

#authorObject



29
30
31
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 29

def author
  latest_commit.author.name
end

#current?Boolean



13
14
15
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 13

def current?
  local? && branch.current
end

#has_tracking_branch?Boolean



25
26
27
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 25

def has_tracking_branch?
  local? && upstream
end

#local?Boolean



17
18
19
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 17

def local?
  !remote?
end

#nameObject



33
34
35
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 33

def name
  branch.name
end

#remote?Boolean



21
22
23
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 21

def remote?
  !branch.remote.to_s.empty?
end

#startObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 37

def start
  # WIP if necessary

  repo.with_branch(name) do
    ensure_upstream
  end

  # if selected_branch.has_wip_commit? && yes?("There is a WIP commit on this bra
  # nch, would you like to apply it locally?")
  #   repo.rollback
  #
  #   say "The WIP commit has been applied."
  #
  #   if yes?("Would you like to remove the commit from origin?")
  #     repo.push(branch: selected_branch, force: true)
  #   end
  # end
end

#version_numberObject



56
57
58
# File 'lib/hustle_and_flow/version_controls/git/branch.rb', line 56

def version_number
  name[/v(\d+)\z/, 1].to_i
end