Commit eac18992 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

hg_git_repo: implement hg_call() a primitive method

This method will help us to easily run any hg command; and
it will automatically prepare the env and other such thigns.

--HG--
branch : heptapod
parent d36b1d5b79e9
Pipeline #13760 skipped with stages
......@@ -490,6 +490,41 @@ def hg_changeset_publish(user, hgsha, notify_gitlab: false, for_mr_iid: nil)
raise HgError, "Could not publish changeset #{hgsha}: #{out}" unless status.zero?
end
# Perform a Mercurial command
#
# `args` - list of command arguments for `hg` executable
# `user` - user object responsible for running the hg command
# `path` - the working directory path, typically obtained with `hg share`
# `for_write` - if true, we prepare the env of write access for user
# `success_code_can_be_one` - flags that success return code for hg command being run, can be 1
# `force_system_user` - force to use system user over Rails user
def hg_call(args, user, path, env: nil, for_write: false,
success_code_can_be_one: false,
force_system_user: false)
if env.nil?
if for_write
env = hg_env_for_write(user, force_system_user: force_system_user)
else
env = { 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
end
end
username = hg_prepare_user_encoding(env, user, "")
cmd = [Gitlab.config.mercurial.bin_path,
'--config', 'ui.username=' + username] + args
output, status = popen(cmd, path, env)
if for_write
hg_git_invalidate_maps!
end
if status != 0
if status == 1 && success_code_can_be_one
# cmd passed with return code 1
else
raise HgError, "Command failed (status code #{status}): "\
"'#{output}' command was: #{cmd}"
end
end
end
# Perform a Mercurial commit
#
# `path` - the working directory path, typically obtained with `hg share`
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment