aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-01-30 17:08:07 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-01-30 17:08:07 -0500
commitc47a47d8890a855f30dcd00676489ac19dbefe74 (patch)
tree3a3ff6fc33695e56f725ae01dd066818d5614933
parentd0889f1b2000525d77c7d9b8e4a7ac977d550504 (diff)
downloadb4-c47a47d8890a855f30dcd00676489ac19dbefe74.tar.gz
init: don't crash when user.name or user.email arent't set
A small regression that was causing a crash if user.email was not set in either ~/.gitconfig or env. Fixes: ccdafeadb85 ("init: separate config setup from access") Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/__init__.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index 0f39e39..06a0518 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -1022,10 +1022,14 @@ class LoreTrailer:
msg: Optional[email.message.Message] = None):
if name is None:
self.name = 'Signed-off-by'
- ucfg = get_user_config()
- self.value = '%s <%s>' % (ucfg['name'], ucfg['email'])
self.type = 'person'
- self.addr = (ucfg['name'], ucfg['email'])
+ ucfg = get_user_config()
+ try:
+ self.value = '%s <%s>' % (ucfg['name'], ucfg['email'])
+ self.addr = (ucfg['name'], ucfg['email'])
+ except KeyError:
+ self.value = 'User Not Set <email@not.set>'
+ self.addr = ('User Not Set', 'email@not.set')
else:
self.name = name
self.value = value
@@ -2931,10 +2935,20 @@ def _setup_user_config(cmdargs: argparse.Namespace):
USER_CONFIG = get_config_from_git(r'user\..*')
if 'name' not in USER_CONFIG:
- udata = pwd.getpwuid(os.getuid())
- USER_CONFIG['name'] = udata.pw_gecos
+ if 'GIT_COMMITTER_NAME' in os.environ:
+ USER_CONFIG['name'] = os.environ['GIT_COMMITTER_NAME']
+ elif 'GIT_AUTHOR_NAME' in os.environ:
+ USER_CONFIG['name'] = os.environ['GIT_AUTHOR_NAME']
+ else:
+ udata = pwd.getpwuid(os.getuid())
+ USER_CONFIG['name'] = udata.pw_gecos
if 'email' not in USER_CONFIG:
- USER_CONFIG['email'] = os.environ['EMAIL']
+ if 'GIT_COMMITTER_EMAIL' in os.environ:
+ USER_CONFIG['email'] = os.environ['GIT_COMMITTER_EMAIL']
+ elif 'GIT_AUTHOR_EMAIL' in os.environ:
+ USER_CONFIG['email'] = os.environ['GIT_AUTHOR_EMAIL']
+ elif 'EMAIL' in os.environ:
+ USER_CONFIG['email'] = os.environ['EMAIL']
_cmdline_config_override(cmdargs, USER_CONFIG, 'user')