Add simple tool for 'gitlab-hg' for on server repository maintenance.
Occasionally, I need to do repository maintenance(e.g. repo mirrors get out of sync and commits need to be stripped). On the FAQ, there's warning about using the wrong mercurial version/configuration.
I propose a small simplification that parses the config/gitlab.yml
for the correct configuration, like the following:
#!/opt/gitlab/embedded/bin/python3
import yaml
import subprocess
import os
import sys
gitlab_yml = yaml.safe_load( open('/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml', 'r') )
production = gitlab_yml.get('production')
hgrc = production.get('mercurial').get('hgrc')
hg_bin = production.get('mercurial').get('bin_path')
os.environ['HGRCPATH'] = ':'.join(hgrc)
subprocess.run([ hg_bin ] + sys.argv[1:])
If this is installed in the /opt/gitlab/embedded/bin directory the paths could be relative to the location of the script itself.