unjs / giget

✨ Download templates and git repositories with pleasure!
MIT License
446 stars 37 forks source link

Get git commit id from tarball #106

Open endersonmaia opened 1 year ago

endersonmaia commented 1 year ago

Describe the feature

I'd like to inform the user what is the git commit hash that is being downloaded when a branch or tag is passed.

Since giget doesn't depend on git, we'd need to assume that the tarball downloaded from the providers are generated using git archive.

If that's the case, the commit id could be retrieved from the tarball.

Example:

wget https://codeload.github.com/unjs/giget/tar.gz/tags/v1.1.2
zcat v1.1.2 | git get-tar-commit-id
8ddd2a4eb6045710c1bac9761e97152cf6af4b8a

https://github.com/unjs/giget/commit/8ddd2a4eb6045710c1bac9761e97152cf6af4b8a

Additional information

pi0 commented 1 year ago

Interesting idea. I think somehow we should extract such metadata from tar archive. We use node-tar internally might be a way to retrieve commit id.

endersonmaia commented 1 year ago

Reference: https://github.com/git/git/blob/master/builtin/get-tar-commit-id.c

pi0 commented 1 year ago

Thanks. Seems reading is not that hard even if node-tar does not supports, we can easily find comment header: (update we can: https://github.com/isaacs/node-tar#class-tarpax)

> head release.tar
pax_global_header00006660000000000000000000000064143737264400014524gustar00rootroot0000000000000052 comment=8ddd2a4eb6045710c1bac9761e97152cf6af4b8a