diff --git a/codearchiver/modules/git.py b/codearchiver/modules/git.py index 2d0b2c3..f50938c 100644 --- a/codearchiver/modules/git.py +++ b/codearchiver/modules/git.py @@ -18,6 +18,7 @@ class GitMetadata(codearchiver.core.Metadata): codearchiver.core.MetadataField(key = 'Git version', required = True, repeatable = False), codearchiver.core.MetadataField(key = 'Based on bundle', required = False, repeatable = True), codearchiver.core.MetadataField(key = 'Ref', required = True, repeatable = True), + codearchiver.core.MetadataField(key = 'Head', required = True, repeatable = False), codearchiver.core.MetadataField(key = 'Root commit', required = True, repeatable = True), codearchiver.core.MetadataField(key = 'Object', required = False, repeatable = True), ) @@ -75,6 +76,11 @@ class Git(codearchiver.core.Module): rootCommits = list(filter(None, rootCommits.splitlines())) _, objects, _ = codearchiver.subprocess.run_with_log(['git', 'cat-file', '--batch-check', '--batch-all-objects', '--unordered', '--buffer'], cwd = directory) objects = {oid: otype for oid, otype, osize in map(functools.partial(str.split, sep = ' '), objects.splitlines())} + with open(os.path.join(directory, 'HEAD'), 'r') as fp: + head = fp.read() + if not head.startswith('ref: refs/heads/') or not head.endswith('\n'): + raise RuntimeError(f'Unexpected HEAD content: {head!r}') + head = head[:-1] # Remove trailing \n # Check whether there are relevant prior bundles to create an incremental one commitsAndTags = {oid for oid, otype in objects.items() if otype in ('commit', 'tag')} @@ -168,6 +174,7 @@ class Git(codearchiver.core.Module): metadata.append('Based on bundle', oldBundle) for line in refs: metadata.append('Ref', line) + metadata.append('Head', head) for commitId in rootCommits: metadata.append('Root commit', commitId) for oid, otype in indexObjects.items():