Commit 7f97345c 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.
parent d36b1d5b79e9
Pipeline #13760 skipped with stages
......@@ -490,6 +490,41 @@
raise HgError, "Could not publish changeset #{hgsha}: #{out}" unless
# 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)
env = { 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
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
if status != 0
if status == 1 && success_code_can_be_one
# cmd passed with return code 1
raise HgError, "Command failed (status code #{status}): "\
"'#{output}' command was: #{cmd}"
# Perform a Mercurial commit
# `path` - the working directory path, typically obtained with `hg share`
Supports Markdown
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