class VersionManager::VCS::Git
Attributes
git[R]
options[R]
Public Class Methods
new(options)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 5 def initialize(options) @options = options @git = ::Git.open(options[:dir], options) end
Public Instance Methods
add_tag(tag_name, message)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 36 def add_tag(tag_name, message) git.add_tag(tag_name, message: message, annotate: tag_name) end
checkout(branch)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 16 def checkout(branch) git.branch(branch_name(branch)).checkout end
commit(filepath, message)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 31 def commit(filepath, message) git.lib.send(:command, 'add', filepath) git.lib.send(:command, 'commit', ['-m', message.to_s, '-o', filepath.to_s]) end
create_branch!(branch)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 10 def create_branch!(branch) branch = branch_name(branch) raise VersionManager::VCS::BranchAlreadyExistsError, branch if branch_exists?(branch) checkout(branch) end
current_branch()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 49 def current_branch git.current_branch end
master_state_actual?()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 53 def master_state_actual? git.revparse(master_branch_name) == git.revparse(remote_master_branch_name) end
push()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 40 def push git.pull(remote, current_branch) if find_remote_branch(current_branch) git.push(remote, current_branch) end
push_tag(tag_name)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 45 def push_tag(tag_name) git.push(remote, tag_name) end
remote_branch_names()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 64 def remote_branch_names git_remote['remotes'].keys end
show_file(branch, filepath)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 24 def show_file(branch, filepath) relative_filepath = Pathname.new(filepath).relative_path_from(Pathname.new(options[:dir])).to_s git.object("#{remote}/#{branch_name(branch)}:#{relative_filepath}").contents rescue StandardError nil end
state_actual?()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 57 def state_actual? head = git_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)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 20 def switch_branch(branch) # checkout moves commits to new branch git.lib.send(:command, 'checkout', branch_name(branch)) end
Private Instance Methods
branch_exists?(branch_name)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 76 def branch_exists?(branch_name) branches = git_remote['branches'].keys + git_remote['remotes'].keys branches.any? { |b| b.split('/').last == branch_name } end
branch_name(version)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 72 def branch_name(version) VCS.branch_name(version, options) end
find_remote_branch(branch_name)
click to toggle source
# File lib/version-manager/vcs/git.rb, line 89 def find_remote_branch(branch_name) remote_branch_names.find { |remote| branch_name == remote.split('/').last } end
git_remote()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 97 def git_remote ::Git.ls_remote(options[:dir]) end
master_branch_name()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 81 def master_branch_name options[:master_branch] end
remote()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 93 def remote options[:remote] end
remote_master_branch_name()
click to toggle source
# File lib/version-manager/vcs/git.rb, line 85 def remote_master_branch_name "#{remote}/#{master_branch_name}" end