aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin.ryabitsev@linux.dev>2021-05-28 10:10:52 -0400
committerKonstantin Ryabitsev <konstantin.ryabitsev@linux.dev>2021-05-28 10:10:52 -0400
commit7754d7d35d03b462109c4a93d625f0af21383312 (patch)
treee61f6e5b7238a86451e7d10d1793253a9120b99c
parent6c25d3f80e00610daa93915e869c94f661079e8d (diff)
downloadpatatt-7754d7d35d03b462109c4a93d625f0af21383312.tar.gz
Fix lookups for uncommitted keysv0.4.4
Fix for the case when a key is added the repository but hasn't been committed yet -- we were looking for it in the wrong subpath. Signed-off-by: Konstantin Ryabitsev <konstantin.ryabitsev@linux.dev>
-rw-r--r--patatt/__init__.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/patatt/__init__.py b/patatt/__init__.py
index 9602392..460d282 100644
--- a/patatt/__init__.py
+++ b/patatt/__init__.py
@@ -47,7 +47,7 @@ OPT_HDRS = [b'message-id']
KEYCACHE = dict()
# My version
-__VERSION__ = '0.4.3'
+__VERSION__ = '0.4.4'
MAX_SUPPORTED_FORMAT_VERSION = 1
@@ -723,19 +723,21 @@ def get_public_key(source: str, keytype: str, identity: str, selector: str) -> T
parts = source.split(':', 4)
if len(parts) < 4:
raise ConfigurationError('Invalid ref, must have at least 3 colons: %s' % source)
- gittop = parts[1]
+ gitrepo = parts[1]
gitref = parts[2]
gitsub = parts[3]
- if not gittop:
- gittop = get_git_toplevel()
- if not gittop:
- raise KeyError('Not in a git tree, so cannot use a ref: source')
-
- gittop = os.path.expanduser(gittop)
- if gittop.find('$') >= 0:
- gittop = os.path.expandvars(gittop)
- if os.path.isdir(os.path.join(gittop, '.git')):
- gittop = os.path.join(gittop, '.git')
+ if not gitrepo:
+ gitrepo = get_git_toplevel()
+ if not gitrepo:
+ raise KeyError('Not in a git tree, so cannot use a ref:: source')
+
+ gitrepo = os.path.expanduser(gitrepo)
+ if gitrepo.find('$') >= 0:
+ gitrepo = os.path.expandvars(gitrepo)
+ if os.path.isdir(os.path.join(gitrepo, '.git')):
+ gittop = os.path.join(gitrepo, '.git')
+ else:
+ gittop = gitrepo
# it could omit the refspec, meaning "whatever the current ref"
# grab the key from a fully ref'ed path
@@ -767,8 +769,8 @@ def get_public_key(source: str, keytype: str, identity: str, selector: str) -> T
logger.debug('KEYSRC : %s', keysrc)
return out, 'ref:%s:%s' % (gittop, keysrc)
- # Does it exist on disk in gittop?
- fullpath = os.path.join(gittop, subpath)
+ # Does it exist on disk but hasn't been committed yet?
+ fullpath = os.path.join(gitrepo, subpath)
if os.path.exists(fullpath):
with open(fullpath, 'rb') as fh:
logger.debug('KEYSRC : %s', fullpath)