From 80fc055b1d9dbad128214bef3bae0206c1fa80d5 Mon Sep 17 00:00:00 2001
From: Hans Fangohr <hans.fangohr@mpsd.mpg.de>
Date: Tue, 30 May 2023 19:21:37 +0200
Subject: [PATCH] Set user and email for git commit.

---
 tests.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests.py b/tests.py
index 7a04789..2591515 100644
--- a/tests.py
+++ b/tests.py
@@ -34,8 +34,13 @@ def create_mock_git_repository(target_directory, create_directory=True):
         subprocess.run("echo 'fake content' > readme.txt", shell=True, check=True)
         subprocess.run("git add readme.txt", shell=True, check=True)
         subprocess.run("pwd", shell=True)
+
+        # if email and username are not available (such as on naked test container),
+        # git may complain. We set a temporary user for this one commit to work around
+        # that.
+        user_details = "-c user.name='Tes Ta' -c user.email='tester@some-ci.org'"
         subprocess.run(
-            'git commit -m "first commit" readme.txt', shell=True, check=True
+            f'git {user_details} commit -m "first commit" readme.txt', shell=True, check=True
         )
 
 
-- 
GitLab