Skip to content
Snippets Groups Projects
Commit edbb2385 authored by Georges Racinet's avatar Georges Racinet
Browse files

native mode: configuring through process environment variables

This is part of heptapod#364.

Heptapod Shell cannot pass `--config` command-line arguments,
because that is rightfully considered a potential security
breach (it would allow to register a hook, hence for arbitrary
code execution).

So we resort to an environment variable. It will actually
also be more practical for the Rails app (only one method,
the env creator, to patch)
parent 31d7839f
No related branches found
No related tags found
1 merge request!34Triggering Mercurial native mode from environment variables and HTTP headers
......@@ -97,6 +97,13 @@
elif auto_publish == b'all':
ui.setconfig(b'phases', b'publish', True)
# here it would be tempting to use pop() but this is called twice
# for each `hg` invocation, and apparently the default is reapplied between
# the two calls.
env_native = ui.environ.get(b'HEPTAPOD_HG_NATIVE', None)
if env_native is not None:
ui.setconfig(b'heptapod', b'native', env_native)
@command(
b"pull-force-topic",
......
......@@ -552,6 +552,7 @@
ui = self.repo.ui
native = ui.configbool(b'heptapod', b'native')
ui.note(b"heptapod_notify_gitlab heptapod.native=%r" % native)
if native and prune_reasons:
prune_reasons = {gl_branch: reason.convert_native(self)
......
......@@ -8,7 +8,10 @@
import pytest
from heptapod.testhelpers import LocalRepoWrapper
from mercurial import pycompat
from mercurial import (
encoding,
pycompat,
)
from .utils import common_config
......@@ -70,3 +73,20 @@
ui = make_repo(tmpdir, config={section: {item: value}})
assert ui.configbool(pycompat.sysbytes(section),
pycompat.sysbytes(item)) == value
@parametrize('env_value,expected', (('yes', True), ('no', False)))
def test_native_from_env(env_value, expected, tmpdir, monkeypatch):
env = dict(encoding.environ)
env_key = b'HEPTAPOD_HG_NATIVE'
env_value = env_value.encode()
env[env_key] = env_value
monkeypatch.setattr(encoding, 'environ', env)
ui = make_repo(tmpdir, {})
# confirm that test patching worked
assert ui.environ[env_key] == env_value
# actual test assertions
assert ui.config(b'heptapod', b'native') == env_value
assert ui.configbool(b'heptapod', b'native') is expected
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment