From adbbcc9a47c64d2c6de71012c498f7d5734f810d Mon Sep 17 00:00:00 2001 From: Catherine Date: Thu, 22 Oct 2026 22:28:30 +0000 Subject: [PATCH] Extract commit information out of `git archive` output. --- src/extract.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/extract.go b/src/extract.go index 03f6555..13f2a5b 100644 --- a/src/extract.go +++ b/src/extract.go @@ -15,7 +15,9 @@ import ( "strings" "github.com/c2h5oh/datasize" + "github.com/go-git/go-git/v6/plumbing" "github.com/klauspost/compress/zstd" + "google.golang.org/protobuf/proto" ) var ErrArchiveTooLarge = errors.New("archive too large") @@ -131,6 +133,16 @@ func ExtractTar(ctx context.Context, reader io.Reader, oldManifest *Manifest) (* } case tar.TypeDir: AddDirectory(manifest, fileName) + case tar.TypeXGlobalHeader: + // `git-archive ` puts the commit hash in the `comment` field. We stash + // this into the manifest when the format looks right. Unlike when we do the clone, + // there's no actual guarantee that the commit sha is real; however since the repo + // contents is user-supplied and untrusted in first place, this should be fine. + if comment, found := header.PAXRecords["comment"]; found { + if _, ok := plumbing.FromHex(comment); ok { + manifest.Commit = proto.String(comment) + } + } default: AddProblem(manifest, fileName, "tar: unsupported type '%c'", header.Typeflag) continue -- knotmirror 0.0.1