class DTK::Client::Operation::ClientModuleDir::GitRepo

Operations for managing module folders that are git repos

Constants

DEFAULT_NUM_DTKN_FETCH_RETRIES

The retries are put in to avoid race condition when the keys are not yet in repo manager gitolite

SLEEP_BETWEEN_RETRIES

Public Class Methods

add_service_repo_file(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 200
def self.add_service_repo_file(args)
  wrap_operation(args) do |args| 
    response_data_hash(:repo => Internal.add_service_repo_file(args)) 
  end
end
all_branches(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 218
def self.all_branches(args)
  wrap_operation(args) do |args|
    response_data_hash(:branches => Internal.all_branches(args))
  end
end
checkout_branch(args, &block) click to toggle source

The arg repo wil have a branch. This funbctio checks that out and when finished goes back to current_branch

# File lib/client/operation/client_module_dir/git_repo.rb, line 147
def self.checkout_branch(args, &block)
  wrap_operation(args) do |args|
    repo               = args.required(:repo)
    current_branch     = args.required(:current_branch)
    branch_to_checkout = args.required(:branch_to_checkout)

    Internal.checkout_branch(repo, branch_to_checkout, :current_branch => current_branch, &block)
    response_data_hash
  end
end
clone(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 43
def self.clone(args)
  wrap_operation(args) do |args|
    repo_url        = args.required(:repo_url)
    target_repo_dir = args.required(:target_repo_dir)
    branch          = args.required(:branch)
    response_data_hash(:target_repo_dir => Internal.clone(repo_url, target_repo_dir, branch))
  end
end
clone_exists?(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 36
def self.clone_exists?(args)
  wrap_operation(args) do |args|
    type = args.required(:type)
    local_dir_exists?(type, args.required("#{type}_name".to_sym))
  end
end
clone_module_repo(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 52
def self.clone_module_repo(args)
  wrap_operation(args) do |args|
    response_data_hash(:target_repo_dir => Internal.clone_module_repo(args))
  end
end
commit_and_push_to_nested_module_repo(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 30
def self.commit_and_push_to_nested_module_repo(args)
  wrap_operation(args) do |args|
    response_data_hash(:head_sha => Internal.commit_and_push_to_nested_module_repo(args))
  end
end
commit_and_push_to_service_repo(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 24
def self.commit_and_push_to_service_repo(args)
  wrap_operation(args) do |args| 
    response_data_hash(:head_sha => Internal.commit_and_push_to_service_repo(args))
  end
end
create_add_remote_and_push(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 58
def self.create_add_remote_and_push(args)
  wrap_operation(args) do |args|
    repo_dir      = args.required(:repo_dir)
    repo_url      = args.required(:repo_url)
    remote_branch = args.required(:remote_branch)
    response_data_hash(:head_sha => Internal.create_add_remote_and_push(repo_dir, repo_url, remote_branch))
  end
end
create_empty_git_repo?(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 137
def self.create_empty_git_repo?(args)
  wrap_operation(args) do |args|
    repo_dir = args.required(:repo_dir)
    branch   = args.required(:branch)

    response_data_hash(:repo => Internal.create_empty_git_repo?(repo_dir, :branch => branch))
  end
end
create_empty_repo?(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 67
def self.create_empty_repo?(args)
  wrap_operation(args) do |args|
    repo_dir  = args.required(:repo_dir)
    Internal.create_empty_git_repo?(repo_dir)
    response_data_hash
  end
end
create_repo_with_empty_commit(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 75
def self.create_repo_with_empty_commit(args)
  wrap_operation(args) do |args|
    repo_dir   = args.required(:repo_dir)
    commit_msg = args[:commit_msg]
    repo = Internal.create_empty_git_repo?(repo_dir)
    response_data_hash(:head_sha => Internal.empty_commit(repo, commit_msg))
  end
end
current_branch(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 224
def self.current_branch(args)
  wrap_operation(args) do |args|
    response_data_hash(:branch => Internal.current_branch(args))
  end
end
fetch_dtkn_remote(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 87
def self.fetch_dtkn_remote(args)
  if num_retries = ENV['NUM_DTKN_FETCH_RETRIES']
    num_retries = num_retries.to_i rescue nil
  end
  num_retries ||= DEFAULT_NUM_DTKN_FETCH_RETRIES
  ret = nil
  while num_retries > 0
    num_retries -= 1
    begin
      if ret = fetch_dtkn_remote_single_try(args)
        return ret
      end
    rescue => e
      fail e if num_retries == 0
    end
  end
  ret # should not be reached
end
fetch_merge_and_push(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 167
def self.fetch_merge_and_push(args)
  wrap_operation(args) do |args|
    response_data_hash(:head_sha => Internal.fetch_merge_and_push(args))
  end
end
get_service_repo_file_content(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 206
def self.get_service_repo_file_content(args)
  wrap_operation(args) do |args| 
    response_data_hash(:content => Internal.get_service_repo_file_content(args))
  end
end
init_and_push_from_existing_repo(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 185
def self.init_and_push_from_existing_repo(args)
  wrap_operation(args) do |args|
    repo_dir      = args.required(:repo_dir)
    repo_url      = args.required(:repo_url)
    remote_branch = args.required(:remote_branch)
    response_data_hash(:head_sha => Internal.init_and_push_from_existing_repo(repo_dir, repo_url, remote_branch))
  end
end
local_ahead?(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 127
def self.local_ahead?(args)
  wrap_operation(args) do |args|
    remote_branch = args.required(:remote_branch)
    no_commit     = args[:no_commit]
    repo_with_remote  = repo_with_dtkn_remote(args)

    response_data_hash(:local_ahead => repo_with_remote.local_ahead?(remote_branch, :no_commit => no_commit))
  end
end
merge_from_dtkn_remote(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 116
def self.merge_from_dtkn_remote(args)
  wrap_operation(args) do |args|
    remote_branch    = args.required(:remote_branch)
    no_commit        = args[:no_commit]
    repo_with_remote = repo_with_dtkn_remote(args)
    use_theirs       = args[:use_theirs]

    response_data_hash(:head_sha => repo_with_remote.merge_from_remote(remote_branch, :no_commit => no_commit, :use_theirs => use_theirs))
  end
end
modified(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 173
def self.modified(args)
  wrap_operation(args) do |args|
    response_data_hash(:modified => Internal.modified(args))
  end
end
modified_with_diff(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 179
def self.modified_with_diff(args)
  wrap_operation(args) do |args|
    response_data_hash(:modified => Internal.modified(args, :with_diffs => true))
  end
end
pull_from_remote(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 194
def self.pull_from_remote(args)
  wrap_operation(args) do |args|
    response_data_hash(:target_repo_dir => Internal.pull_from_remote(args))
  end
end
pull_from_service_repo(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 212
def self.pull_from_service_repo(args)
  wrap_operation(args) do |args| 
    response_data_hash(:repo => Internal.pull_from_service_repo(args)) 
  end
end
reset_hard(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 230
def self.reset_hard(args)
  wrap_operation(args) do |args|
    remote_branch    = args.required(:remote_branch)
    repo_with_remote = repo_with_dtkn_remote(args)
    branch           = args[:branch]
    response_data_hash(:head_sha => repo_with_remote.reset_hard(remote_branch, :branch => branch))
  end
end
stage_and_commit(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 158
def self.stage_and_commit(args)
  wrap_operation(args) do |args| 
    repo_dir          = args.required(:repo_dir)
    local_branch_type = args.required(:local_branch_type)
    commit_msg        = args[:commit_msg]
    response_data_hash(:head_sha => Internal.stage_and_commit(repo_dir, local_branch_type, :commit_msg => commit_msg))
  end
end

Private Class Methods

fetch_dtkn_remote_single_try(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 106
def self.fetch_dtkn_remote_single_try(args)
  wrap_operation(args) do |args|
    repo_with_remote = repo_with_dtkn_remote(args)

    repo_with_remote.fetch
    response_data_hash
  end
end
repo_with_dtkn_remote(args) click to toggle source
# File lib/client/operation/client_module_dir/git_repo.rb, line 241
def self.repo_with_dtkn_remote(args)
  info_type = args.required(:info_type)
  repo_dir  = args.required(:repo_dir)
  Internal::Dtkn.repo_with_remote(info_type, repo_dir, add_remote: args[:add_remote])
end