Reputation: 4620
I would like to get commit metadata like that returned by the git cat-file -p <COMMIT-ID>
(see this example from Git itself)
$ git cat-file -p a4ee444
tree 34f4cce68fd066d044dcbca866a161fa5c98dc6b
parent 1f9c1fab6421402a9c893a2fcd35fb4cf6116166
parent ffa952497288d29d94b16675c6789ef83850def3
author Junio C Hamano <[email protected]> 1518737095 -0800
committer Junio C Hamano <[email protected]> 1518737095 -0800
mergetag object ffa952497288d29d94b16675c6789ef83850def3
type commit
tag v2.16.2
tagger Junio C Hamano <[email protected]> 1518737031 -0800
Git 2.16.2
-----BEGIN PGP SIGNATURE-----
...
-----END PGP SIGNATURE-----
Sync with 2.16.2
* tag 'v2.16.2':
Git 2.16.2
but without having to fetch the entire commit with all its files.
Does anyone know if it is possible to get this remote information via the git
client program, or by some other means, like using Git's internal transfer protocols?
Thanks
Upvotes: 1
Views: 1286
Reputation: 94511
You can get information about a commit using GitHub API.
For example using curl
in command line:
curl -X GET https://api.github.com/repos/phdru/ppu/git/commits/63c535d7c6b151c210e344dd4b745407f3911d76
(this is a commit from my repository)
For authentication pass -u
:
curl -u user:password …
Upvotes: 1
Reputation: 488453
is [it] possible to get this remote information via the git client program,
No: even with shallow clones, the clients "want" all the objects that are needed to complete a commit.
or by some other means, like using Git's internal transfer protocols?
Possibly, as long as there is a name pointing to it, or the server is running on a repository that has uploadpack.allowReachableSHA1InWant
configured to true
, or has uploadpack.allowAnySHA1InWant
configured to true
. Senders don't normally negotiate about tree objects, though: they just assume that you have objects reachable from commits that you (as a receiver) say that you have. So it's not designed to work this way.
Note that the PGP signature in a mergetag object ...
header inside a commit is simply copied from the annotated tag. I have not tried it, but a shallow clone with depth zero might work to retrieve all tags (only). In this case, you could just look at the tag object. This part is designed to work this way, and seems more promising. Moreover, annotated tag objects normally have tag names pointing to them, so you don't need the special uploadpack
configuration entries: these objects are directly published and hence always "want"-able.
(Of course you would have to find the right tag name, and it's not clear how you would do that without the commit data. On the other hand, it's not clear how you would find the commit hash in the first place.)
The actual tag object in this case is:
$ git rev-parse v2.16.2
86aabcca24951ccfb9392014c8a379992434a7df
$ git cat-file -p v2.16.2
object ffa952497288d29d94b16675c6789ef83850def3
type commit
tag v2.16.2
tagger Junio C Hamano <[email protected]> 1518737031 -0800
Git 2.16.2
-----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEE4fA2sf7nIh/HeOzvsLXohpav5ssFAlqGFocACgkQsLXohpav
5svXQBAAvNnbVRImTzETgfwBNwl8qEfEVJb6OTVoPF6IiPwaWCu/tTlS7X4wml7S
e9s6ZyXzVRRJSDts6hln+V5FAESpLdwSEj2vWdId8ipafSUp2OnZvb7tHYgV3RCb
01PrJtA5h/RywwGO8OSZP6hEi5GlBvKXOxg76Yw8LVanP0/9CUBP3Fn+Gh55Th3B
1tL8GXwQg8pADcl9Yx4X82YkGq672SShRiu3WAcuZY9BOdMDt18hebl2JHUkGT1K
jwm06aLmb9zIczNqFZqu9h/nvnxvM2lbHHQ6JpyIvObXCLVzzxvtso8ilEVDlEwo
RYPAe8a7gDuIls7ziff9a0fSTlTd1sY3l1FSJLg73jB+j/sP0pTaTN2a2XfoFqLS
oV1h7AwOA9AOn+bp3kKWOIuqHcZVHU68wHa4z3fyi6vWUEWMpsY3KZ2zY0cEce9i
SJKk5y2HYk4jCv72n0XC4WIgexkn23Btr58u9+zNraecyO0EwzGfrouiruh6zfve
DCieVcYDy7y50yhI2ES+RIJvGPPp8RRFXEfjLUSyGEJgDxuJqhp3oZadqGRSwVeN
NjOEr46zhHvd4jiGNL6409v5PeViKRdOhqOf0oikYQwzNOAeu8fXtx/8Fc2X/KW5
DNaz4oxo/GwGfaGI7w1IsiH4HcGVMJXQokc1Lmvv5kEx6iXp7q0=
=rp/y
-----END PGP SIGNATURE-----
Upvotes: 3