class DTK::Network::Client::GitRepo
Public Class Methods
add_remote(repo, remote_name, remote_url)
click to toggle source
# File lib/client/git_repo.rb, line 81 def self.add_remote(repo, remote_name, remote_url) repo.add_remote(remote_name, remote_url) remote_name end
add_remote_and_publish(git_args)
click to toggle source
# File lib/client/git_repo.rb, line 3 def self.add_remote_and_publish(git_args) Command.wrap_command(git_args) do |git_args| repo_dir = git_args.required(:repo_dir) remote_url = git_args.required(:remote_url) local_branch = git_args[:branch] || 'master' remote_branch = git_args[:remote_branch] || local_branch remote = git_args[:remote] || 'origin' repo = git_repo.new(repo_dir, :branch => local_branch) create_if_missing = local_branch_exist?(repo, local_branch) ? false : true repo.checkout(local_branch, new_branch: create_if_missing) repo.add_all repo.commit("Publish from dtk client", :allow_empty => true) add_remote_and_push(repo, remote, remote_url, remote_branch) end end
add_remote_and_pull(repo, remote, remote_url, local_branch, remote_branch, opts = {})
click to toggle source
# File lib/client/git_repo.rb, line 105 def self.add_remote_and_pull(repo, remote, remote_url, local_branch, remote_branch, opts = {}) repo.add_remote(remote, remote_url) opts[:force] ? force_pull(repo, remote, remote_branch) : reset_if_error(repo, local_branch) { repo.pull(remote, remote_branch) } end
add_remote_and_push(repo, remote, remote_url, remote_branch, opts = {})
click to toggle source
# File lib/client/git_repo.rb, line 100 def self.add_remote_and_push(repo, remote, remote_url, remote_branch, opts = {}) repo.add_remote(remote, remote_url) repo.push(remote, remote_branch, opts) end
all_branches(args)
click to toggle source
def self.add_remote_and_push(repo, repo_url, remote_branch)
repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url) repo.stage_and_commit repo.push(Dtk_Server::GIT_REMOTE, remote_branch, { :force => true })
end
# File lib/client/git_repo.rb, line 207 def self.all_branches(args) repo_url = args.required(:path) repo = git_repo.new(repo_url) repo.all_branches end
create_empty_git_repo?(repo_dir, opts = {})
click to toggle source
opts can have keys
:branch
returns object of type DTK::Client::GitRepo
# File lib/client/git_repo.rb, line 71 def self.create_empty_git_repo?(repo_dir, opts = {}) git_repo.new(repo_dir, :branch => opts[:branch]) end
current_branch(args)
click to toggle source
# File lib/client/git_repo.rb, line 213 def self.current_branch(args) repo_url = args.required(:path) repo = git_repo.new(repo_url) repo.current_branch.name end
empty_commit(repo, commit_msg = nil)
click to toggle source
returns head_sha
# File lib/client/git_repo.rb, line 76 def self.empty_commit(repo, commit_msg = nil) repo.empty_commit(commit_msg) repo.head_commit_sha end
fetch(repo, remote_name)
click to toggle source
# File lib/client/git_repo.rb, line 86 def self.fetch(repo, remote_name) repo.fetch(remote_name) end
force_pull(repo, remote, remote_branch)
click to toggle source
# File lib/client/git_repo.rb, line 110 def self.force_pull(repo, remote, remote_branch) repo.fetch(remote) repo.reset_hard("#{remote}/#{remote_branch}") end
git_repo()
click to toggle source
# File lib/client/git_repo.rb, line 219 def self.git_repo GitClient end
local_ahead?(repo, merge_from_ref, opts = {})
click to toggle source
# File lib/client/git_repo.rb, line 130 def self.local_ahead?(repo, merge_from_ref, opts = {}) base_sha = repo.head_commit_sha remote_branch = repo.all_branches.remote.find { |r| "#{r.remote}/#{r.name}" == merge_from_ref } remote_sha = remote_branch.gcommit.sha repo.local_ahead(base_sha, remote_sha) end
local_branch_exist?(repo, branch)
click to toggle source
# File lib/client/git_repo.rb, line 115 def self.local_branch_exist?(repo, branch) local_branches = branch.is_a?(String) ? repo.all_branches.local.map { |branch| branch.name } : (repo.all_branches.local || []) local_branches.include?(branch) end
merge(repo, merge_from_ref, opts = {})
click to toggle source
opts can have keys
:no_commit
# File lib/client/git_repo.rb, line 122 def self.merge(repo, merge_from_ref, opts = {}) base_sha = repo.head_commit_sha repo.merge(merge_from_ref, :use_theirs => opts[:use_theirs]) # the git gem does not take no_commit as merge argument; so doing it with soft reset repo.reset_soft(base_sha) if opts[:no_commit] repo.head_commit_sha end
pull_from_remote(git_args)
click to toggle source
# File lib/client/git_repo.rb, line 48 def self.pull_from_remote(git_args) Command.wrap_command(git_args) do |git_args| repo_dir = git_args.required(:repo_dir) remote_url = git_args.required(:remote_url) local_branch = git_args[:branch] || 'master' remote_branch = git_args[:remote_branch] || local_branch remote = git_args[:remote] || 'origin' force = git_args[:force] repo = git_repo.new(repo_dir, :branch => local_branch) repo.checkout(local_branch) if repo.is_there_remote?(remote) pull_when_there_is_remote(repo, remote, remote_url, local_branch, remote_branch, { force: force }) else add_remote_and_pull(repo, remote, remote_url, local_branch, remote_branch, { force: force }) end end end
pull_when_there_is_remote(repo, remote, remote_url, local_branch, remote_branch, opts = {})
click to toggle source
# File lib/client/git_repo.rb, line 95 def self.pull_when_there_is_remote(repo, remote, remote_url, local_branch, remote_branch, opts = {}) repo.remove_remote(remote) add_remote_and_pull(repo, remote, remote_url, local_branch, remote_branch, opts) end
push_to_remote(git_args)
click to toggle source
# File lib/client/git_repo.rb, line 21 def self.push_to_remote(git_args) Command.wrap_command(git_args) do |git_args| repo_dir = git_args.required(:repo_dir) remote_url = git_args.required(:remote_url) local_branch = git_args[:branch] || 'master' remote_branch = git_args[:remote_branch] || local_branch remote = git_args[:remote] || 'origin' commit_msg = git_args[:commit_msg] || "Push from dtkn client" force = git_args[:force] repo = git_repo.new(repo_dir, :branch => local_branch) create_if_missing = local_branch_exist?(repo, local_branch) ? false : git_args[:create_if_missing] repo.checkout(local_branch, new_branch: create_if_missing) repo.add_all repo.commit(commit_msg, :allow_empty => true) diffs = repo.diff_name_status("#{remote}/#{remote_branch}") if repo.is_there_remote?(remote) push_when_there_is_remote(repo, remote, remote_url, remote_branch, { force: force }) else add_remote_and_push(repo, remote, remote_url, remote_branch, { force: force }) end diffs end end
push_when_there_is_remote(repo, remote, remote_url, remote_branch, opts = {})
click to toggle source
# File lib/client/git_repo.rb, line 90 def self.push_when_there_is_remote(repo, remote, remote_url, remote_branch, opts = {}) repo.remove_remote(remote) add_remote_and_push(repo, remote, remote_url, remote_branch, opts) end
reset_hard(repo, merge_from_ref)
click to toggle source
# File lib/client/git_repo.rb, line 223 def self.reset_hard(repo, merge_from_ref) repo.reset_hard(merge_from_ref) repo.head_commit_sha end
reset_if_error(repo, branch) { || ... }
click to toggle source
# File lib/client/git_repo.rb, line 228 def self.reset_if_error(repo, branch, &block) ret = nil begin sha_before_operations = repo.revparse(branch) ret = yield rescue => e # reset to enable checkout of another branch repo.add_all repo.reset_hard(sha_before_operations) raise e end ret end
stage_and_commit(repo_dir,local_branch_type, opts = {})
click to toggle source
opts can have keys:
:commit_msg
returns head_sha
# File lib/client/git_repo.rb, line 140 def self.stage_and_commit(repo_dir,local_branch_type, opts = {}) local_branch = branch_from_local_branch_type(local_branch_type) repo = create_empty_git_repo?(repo_dir, :branch => local_branch) repo.stage_and_commit(opts[:commit_msg]) repo.head_commit_sha end