[PATCH 1 of 2] tests: set Git author and committer name and email settings explicitly
Manuel Jacob
me at manueljacob.de
Thu Mar 30 01:37:57 UTC 2023
# HG changeset patch
# User Manuel Jacob <me at manueljacob.de>
# Date 1680121377 -7200
# Wed Mar 29 22:22:57 2023 +0200
# Node ID 2304f8da62b03f6cfd966b72eec70c38c4d52e37
# Parent 7037365a7bc351b81f05c790c6d3417d81d7bd5d
# EXP-Topic tests-git
tests: set Git author and committer name and email settings explicitly
Passing at least GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL as environment variables is necessary on my machine, which has the user.useconfigonly config set. The author could be passed via command-line options, but it seems best to pass everything uniformly.
diff --git a/kallithea/tests/other/test_vcs_operations.py b/kallithea/tests/other/test_vcs_operations.py
--- a/kallithea/tests/other/test_vcs_operations.py
+++ b/kallithea/tests/other/test_vcs_operations.py
@@ -167,6 +167,23 @@
return tempfile.mkdtemp(dir=base.TESTS_TMP_PATH, prefix=prefix, suffix=suffix)
+email = 'me at example.com'
+if os.name == 'nt':
+ name = 'User'
+else:
+ name = 'User ǝɯɐᴎ'
+
+HG_USER = '%s <%s>' % (name, email)
+# If the user.useconfigonly config is set, Git won't try to auto-detect the
+# name and email. For this case, we need to pass them as environment variables.
+GIT_NAME_AND_EMAIL_ENV_VARS = dict(
+ GIT_AUTHOR_NAME=name,
+ GIT_AUTHOR_EMAIL=email,
+ GIT_COMMITTER_NAME=name,
+ GIT_COMMITTER_EMAIL=email,
+)
+
+
def _add_files(vcs, dest_dir, files_no=3):
"""
Generate some files, add it to dest_dir repo and push back
@@ -179,24 +196,18 @@
open(os.path.join(dest_dir, added_file), 'a').close()
Command(dest_dir).execute(vcs, 'add', added_file)
- email = 'me at example.com'
- if os.name == 'nt':
- author_str = 'User <%s>' % email
- else:
- author_str = 'User ǝɯɐᴎ <%s>' % email
for i in range(files_no):
cmd = """echo "added_line%s" >> %s""" % (i, added_file)
Command(dest_dir).execute(cmd)
if vcs == 'hg':
cmd = """hg commit -m "committed new %s" -u "%s" "%s" """ % (
- i, author_str, added_file
+ i, HG_USER, added_file
)
elif vcs == 'git':
- cmd = """git commit -m "committed new %s" --author "%s" "%s" """ % (
- i, author_str, added_file
+ cmd = """git commit -m "committed new %s" "%s" """ % (
+ i, added_file
)
- # git commit needs EMAIL on some machines
- Command(dest_dir).execute(cmd, EMAIL=email)
+ Command(dest_dir).execute(cmd, **GIT_NAME_AND_EMAIL_ENV_VARS)
def _add_files_and_push(webserver, vt, dest_dir, clone_url, ignoreReturnCode=False, files_no=3):
_add_files(vt.repo_type, dest_dir, files_no=files_no)
@@ -618,7 +629,7 @@
# add submodule
stdout, stderr = Command(base.TESTS_TMP_PATH).execute('git clone', fork_url, dest_dir)
stdout, stderr = Command(dest_dir).execute('git submodule add', clone_url, 'testsubmodule')
- stdout, stderr = Command(dest_dir).execute('git commit -am "added testsubmodule pointing to', clone_url, '"', EMAIL=base.TEST_USER_ADMIN_EMAIL)
+ stdout, stderr = Command(dest_dir).execute('git commit -am "added testsubmodule pointing to', clone_url, '"', **GIT_NAME_AND_EMAIL_ENV_VARS)
stdout, stderr = Command(dest_dir).execute('git push', fork_url, 'master')
# check for testsubmodule link in files page
More information about the kallithea-general
mailing list