class DTK::Network::Client::GitGem
Attributes
git_repo[RW]
Public Class Methods
clone(repo_url, target_path, branch)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 72 def self.clone(repo_url, target_path, branch) git_base = ::Git.clone(repo_url, target_path) begin git_base.checkout(branch) rescue => e raise "The branch or tag '#{branch}' does not exist on repo '#{repo_url}'" end git_base end
new(repo_dir, opts = {})
click to toggle source
opts can have keys
:branch
# File lib/client/git_adapter/git_gem.rb, line 66 def initialize(repo_dir, opts = {}) @repo_dir = repo_dir @git_repo = ::Git.init(repo_dir) @local_branch_name = opts[:branch] end
Public Instance Methods
add(*files)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 191 def add(*files) @git_repo.add(files.flatten) end
add_all()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 195 def add_all # Cannot use '@git_repo.add(:all => true)' because this only works if pwd is base git repo fully_qualified_repo_dir = (@repo_dir =~ /^\// ? @repo_dir : File.join(Dir.pwd, @repo_dir)) @git_repo.add(fully_qualified_repo_dir, :all => true ) end
add_remote(name, url)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 94 def add_remote(name, url) @git_repo.remove_remote(name) if is_there_remote?(name) @git_repo.add_remote(name, url) end
added()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 129 def added status.is_a?(Hash) ? status.added().keys : status.added().collect { |file| file.first } end
all_branches()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 234 def all_branches @git_repo.branches end
changed()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 117 def changed status.is_a?(Hash) ? status.changed().keys : status.changed().collect { |file| file.first } end
changed?()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 229 def changed? (!(changed().empty? && untracked().empty? && deleted().empty?)) end
checkout(branch, opts = {})
click to toggle source
opts can have keys
:new_branch - Boolean
# File lib/client/git_adapter/git_gem.rb, line 84 def checkout(branch, opts = {}) ret = @git_repo.checkout(branch, opts) @local_branch_name = branch ret end
commit(commit_msg = "", opts = {})
click to toggle source
opts can have keys
:allow_empty
# File lib/client/git_adapter/git_gem.rb, line 187 def commit(commit_msg = "", opts = {}) @git_repo.commit(commit_msg, :allow_empty => opts[:allow_empty]) end
current_branch()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 205 def current_branch @git_repo.branches.local.find { |b| b.current } end
deleted()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 125 def deleted status.is_a?(Hash) ? status.deleted().keys : status.deleted().collect { |file| file.first } end
diff()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 221 def diff @git_repo.diff end
diff_name_status(branch_or_sha_1, branch_or_sha_2, opts = {})
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 225 def diff_name_status(branch_or_sha_1, branch_or_sha_2, opts = {}) @git_repo.name_status(branch_or_sha_1, branch_or_sha_2, opts) end
empty_commit(commit_msg = nil)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 143 def empty_commit(commit_msg = nil) commit_msg ||= default_commit_message commit(commit_msg, :allow_empty => true) end
fetch(remote = 'origin')
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 90 def fetch(remote = 'origin') @git_repo.fetch(remote) end
head_commit_sha()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 213 def head_commit_sha current_branch.gcommit.sha end
is_there_remote?(remote_name)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 201 def is_there_remote?(remote_name) @git_repo.remotes.find { |r| r.name == remote_name } end
local_ahead(base_sha, remote_sha)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 164 def local_ahead(base_sha, remote_sha) results = @git_repo.rev_list(base_sha) !results.split("\n").grep(remote_sha).empty? end
merge(branch_to_merge_from, opts = {})
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 109 def merge(branch_to_merge_from, opts = {}) @git_repo.merge(branch_to_merge_from, 'merge', :allow_unrelated_histories => allow_unrelated_histories?, :use_theirs => opts[:use_theirs]) end
pull(remote, branch)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 217 def pull(remote, branch) @git_repo.pull(remote, branch) end
push(remote, branch, opts = {})
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 103 def push(remote, branch, opts = {}) branch_name = current_branch ? current_branch.name : 'master' branch_for_push = "#{branch_name}:refs/heads/#{branch || local_branch_name}" @git_repo.push(remote, branch_for_push, opts) end
remotes()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 209 def remotes @git_repo.remotes end
remove_remote(name)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 99 def remove_remote(name) @git_repo.remove_remote(name) if is_there_remote?(name) end
reset_hard(sha)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 152 def reset_hard(sha) @git_repo.reset_hard(sha) end
reset_soft(sha)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 148 def reset_soft(sha) @git_repo.reset(sha) end
rev_list(base_sha)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 160 def rev_list(base_sha) @git_repo.rev_list(base_sha) end
revparse(sha_or_string)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 156 def revparse(sha_or_string) @git_repo.revparse(sha_or_string) end
stage_and_commit(commit_msg = nil)
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 133 def stage_and_commit(commit_msg = nil) commit_msg ||= default_commit_message add_all begin commit(commit_msg) rescue # do not raise if nothing to commit end end
stage_changes()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 169 def stage_changes() @git_repo.add(untracked()) @git_repo.add(added()) @git_repo.add(changed()) deleted().each do |file| begin @git_repo.remove(file) rescue # ignore this error means file has already been staged # we cannot support status of file, in 1.8.7 so this is # solution for that end end end
status()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 113 def status @git_repo.status end
untracked()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 121 def untracked status.is_a?(Hash) ? status.untracked().keys : status.untracked().collect { |file| file.first } end
Private Instance Methods
default_commit_message()
click to toggle source
# File lib/client/git_adapter/git_gem.rb, line 240 def default_commit_message "DTK Commit from network client" end