Class: VersionManager::VCS::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/version-manager/vcs/git.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Git

Returns a new instance of Git.



4
5
6
7
# File 'lib/version-manager/vcs/git.rb', line 4

def initialize(options)
  @options = options
  @git = ::Git.open(ROOT_DIR, options)
end

Instance Method Details

#add_tag(tag_name, message) ⇒ Object



33
34
35
# File 'lib/version-manager/vcs/git.rb', line 33

def add_tag(tag_name, message)
  git.add_tag(tag_name, message: message, annotate: tag_name)
end

#checkout(branch_name) ⇒ Object



14
15
16
# File 'lib/version-manager/vcs/git.rb', line 14

def checkout(branch_name)
  git.branch(branch_name).checkout
end

#commit(filepath, message) ⇒ Object



28
29
30
31
# File 'lib/version-manager/vcs/git.rb', line 28

def commit(filepath, message)
  git.lib.send(:command, 'add', filepath)
  git.lib.send(:command, 'commit', "-m #{message}", '-o', "#{filepath}")
end

#create_branch!(branch_name) ⇒ Object



9
10
11
12
# File 'lib/version-manager/vcs/git.rb', line 9

def create_branch!(branch_name)
  raise VersionManager::VCS::BranchAlreadyExistsError.new(branch_name) if branch_exists?(branch_name)
  checkout(branch_name)
end

#current_branchObject



46
47
48
# File 'lib/version-manager/vcs/git.rb', line 46

def current_branch
  git.current_branch
end

#master_state_actual?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/version-manager/vcs/git.rb', line 50

def master_state_actual?
  git.revparse(master_branch_name) == git.revparse(remote_master_branch_name)
end

#pushObject



37
38
39
40
# File 'lib/version-manager/vcs/git.rb', line 37

def push
  git.pull(remote, current_branch) if find_remote_branch(current_branch)
  git.push(remote, current_branch)
end

#push_tag(tag_name) ⇒ Object



42
43
44
# File 'lib/version-manager/vcs/git.rb', line 42

def push_tag(tag_name)
  git.push(remote, tag_name)
end

#remote_branch_namesObject



61
62
63
# File 'lib/version-manager/vcs/git.rb', line 61

def remote_branch_names
  ::Git.ls_remote['remotes'].keys
end

#show_file(branch, filepath) ⇒ Object



22
23
24
25
26
# File 'lib/version-manager/vcs/git.rb', line 22

def show_file(branch, filepath)
  git.object("#{branch}:#{filepath}").contents
rescue StandardError
  nil
end

#state_actual?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/version-manager/vcs/git.rb', line 54

def state_actual?
  head = ::Git.ls_remote['branches'][git.current_branch]
  remote_head = find_remote_branch(git.current_branch).last
  return unless remote_head
  head[:sha] == remote_head[:sha]
end

#switch_branch(branch_name) ⇒ Object

checkout moves commits to new branch



18
19
20
# File 'lib/version-manager/vcs/git.rb', line 18

def switch_branch(branch_name) # checkout moves commits to new branch
  git.lib.send(:command, 'checkout', branch_name)
end