debian-mirror-gitlab/spec/support/helpers/bare_repo_operations.rb

45 lines
923 B
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'zlib'
class BareRepoOperations
include Gitlab::Popen
def initialize(path_to_repo)
@path_to_repo = path_to_repo
end
2018-10-15 14:42:47 +05:30
def commit_tree(tree_id, msg, parent: Gitlab::Git::EMPTY_TREE_ID)
2018-03-27 19:54:05 +05:30
commit_tree_args = ['commit-tree', tree_id, '-m', msg]
2018-10-15 14:42:47 +05:30
commit_tree_args += ['-p', parent] unless parent == Gitlab::Git::EMPTY_TREE_ID
2018-03-27 19:54:05 +05:30
commit_id = execute(commit_tree_args)
commit_id[0]
end
2018-03-17 18:26:18 +05:30
private
def execute(args, allow_failure: false)
output, status = popen(base_args + args, nil) do |stdin|
yield stdin if block_given?
end
2020-10-24 23:57:45 +05:30
unless status == 0
2018-03-17 18:26:18 +05:30
if allow_failure
return []
else
raise "Got a non-zero exit code while calling out `#{args.join(' ')}`: #{output}"
end
end
output.split("\n")
end
def base_args
[
Gitlab.config.git.bin_path,
"--git-dir=#{@path_to_repo}"
]
end
end