patman: Support absolute and ~user-relative alias files

Python doesn't naturally support tilde (~) as a user-home marker in
paths, but git-config does. So we need to resolve it before continuing.

We also shouldn't blindly join the top-level tree with the aliasesfile
path, because it might be an absolute path.

This resolves warnings like the following:

  Warning: Cannot find alias file '/path/to/source/tree/~/.git-email'

Seen when git-config is like:

  $ git config sendemail.aliasesfile
  ~/.git-email

Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Otavio Salvador <otavio@ossystems.com.br>
This commit is contained in:
Brian Norris 2022-01-07 15:15:55 -08:00 committed by Simon Glass
parent d8ef446fec
commit dca7926c2c

View File

@ -616,9 +616,14 @@ def GetAliasFile():
"""
fname = command.OutputOneLine('git', 'config', 'sendemail.aliasesfile',
raise_on_error=False)
if fname:
fname = os.path.join(GetTopLevel(), fname.strip())
return fname
if not fname:
return None
fname = os.path.expanduser(fname.strip())
if os.path.isabs(fname):
return fname
return os.path.join(GetTopLevel(), fname)
def GetDefaultUserName():
"""Gets the user.name from .gitconfig file.