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



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

def base_name
  repo_name_parts.join('/')
end

#branchesObject



49
50
51
52
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 49

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

#current_branchObject



54
55
56
57
58
59
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 54

def current_branch
  current = repo.branch(repo.current_branch)

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

#find_or_create_branch(branch_name) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 41

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

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

#organizationObject



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

def organization
  repo_name_parts[0]
end

#upstream_branch_for_branch(branch_name, value = nil) ⇒ Object



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

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



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

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



33
34
35
36
37
38
39
# File 'lib/hustle_and_flow/version_controls/git/repository.rb', line 33

def with_branch(branch_name)
  repo.checkout(branch_name)

  yield

  repo.push('origin', branch_name)
end