Skip to content

Commit 121a814

Browse files
committed
fix: pass user/email via env also for "preset"-auth
GitHelper's "preset"-auth-mode instructs GitHelper to assume underlying git-repository is already configured w.r.t. authentication. However, also for local operations (e.g. create a commit or note), git will require username and email-address. Hence, let GitHelper also pass those (if configured) for preset-case.
1 parent 256310f commit 121a814

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

gitutil.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,18 @@ def _authenticated_remote(self):
149149
git_cfg=self.git_cfg,
150150
)
151151
elif auth_type is AuthType.PRESET:
152-
yield os.environ, self.repo.remotes[0]
152+
cmd_env = os.environ.copy()
153+
if (user := self.git_cfg.user_name):
154+
if not 'GIT_AUTHOR_NAME' in cmd_env:
155+
cmd_env['GIT_AUTHOR_NAME'] = user
156+
if not 'GIT_COMMITTER_NAME' in cmd_env:
157+
cmd_env['GIT_COMMITTER_NAME'] = user
158+
if (email := self.git_cfg.user_email):
159+
if not 'GIT_AUTHOR_EMAIL' in cmd_env:
160+
cmd_env['GIT_AUTHOR_EMAIL'] = email
161+
if not 'GIT_COMMITTER_EMAIL' in cmd_env:
162+
cmd_env['GIT_COMMITTER_EMAIL'] = email
163+
yield cmd_env, self.repo.remotes[0]
153164
return
154165
else:
155166
raise NotImplementedError

0 commit comments

Comments
 (0)