Class: HustleAndFlow::VersionControls::Git::Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Repository

Returns a new instance of Repository.



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

def initialize(path:)
  self.repo = ::Git.open(path)
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



7
8
9
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 7

def repo
  @repo
end

Instance Method Details

#base_nameObject



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

def base_name
  origin_url[%r{github\.com.([\w\-]+/[\w\-]+)}, 1]
end

#branchesObject



45
46
47
48
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 45

def branches
  Branches.new(repo:     self,
               branches: repo.branches)
end

#find_or_create_branch(branch_name) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 37

def find_or_create_branch(branch_name)
  new_branch  = repo.branch(branch_name)
  new_branch.checkout

  Branch.new(repo:   self,
             branch: new_branch)
end

#upstream_branch_for_branch(branch_name, value = nil) ⇒ Object



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

def upstream_branch_for_branch(branch_name, value = nil)
  repo.config(upstream_merge_config_key(branch_name), value)
end

#upstream_remote_for_branch(branch_name, value = nil) ⇒ Object



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

def upstream_remote_for_branch(branch_name, value = nil)
  repo.config(upstream_remote_config_key(branch_name), value)
end

#userObject



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

def user
  repo.config('github.user')
end

#with_branch(branch_name) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 29

def with_branch(branch_name)
  repo.checkout(branch_name)

  yield

  repo.push('origin', branch_name)
end