[PATCH 1 of 2 stable v2] tests: set Git author and committer name and email settings explicitly
Manuel Jacob
me at manueljacob.de
Tue Apr 18 18:35:55 UTC 2023
# HG changeset patch
# User Manuel Jacob <me at manueljacob.de>
# Date 1680121377 -7200
# Wed Mar 29 22:22:57 2023 +0200
# Branch stable
# Node ID 30082bb9719eb00f3be0081b7221d7c3061d4345
# Parent 0a9ddb8cd8c117671ecaf2b4126c3eef09e80ce8
# 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,30 @@
return tempfile.mkdtemp(dir=base.TESTS_TMP_PATH, prefix=prefix, suffix=suffix)
+def _commit(vcs, dest_dir, message, *extra_args):
+ email = 'me at example.com'
+ if os.name == 'nt':
+ name = 'User'
+ else:
+ name = 'User ǝɯɐᴎ'
+
+ return Command(dest_dir).execute(
+ vcs,
+ 'commit',
+ '-m',
+ '"%s"' % message,
+ *extra_args,
+ HGUSER='%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_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 +203,10 @@
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
- )
- elif vcs == 'git':
- cmd = """git commit -m "committed new %s" --author "%s" "%s" """ % (
- i, author_str, added_file
- )
- # git commit needs EMAIL on some machines
- Command(dest_dir).execute(cmd, EMAIL=email)
+ _commit(vcs, dest_dir, "committed new %s" % i, added_file)
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 +628,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 = _commit('git', dest_dir, "added testsubmodule pointing to %s" % clone_url, "-a")
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