Reputation: 77137
I am working in an opscode repo, and need information about a bunch of other repositories. When someone issues a "deploy" command, they may provide a branch or tag (or possibly other refspec) to deploy to. For example…
deploy main_app==1.2.3
deploy main_app workflow_app==4.5.6
deploy app_config==ugly-test-branch
main_app, workflow_app and app_config are all in different repos, and none are in the repo that I'm currently in.
For each repo, I want to determine if the given refspec exists, and if it is not a branch, what branch is it in?
I can answer the first question with git ls-remote
, but is there a way to tell what branch an object is in without at least doing a git clone --bare
?
Upvotes: 1
Views: 1132
Reputation: 488599
For each repo, I want to determine if the given refspec exists
These names (1.2.3
and the like) are not really refspecs but rather just "names", and unqualified ones at that. Of course, refspecs—whose general form is +name1:name2
with some parts being optional and the two names not necessarily fully qualified—do admit a simple name, but the idea here is that a refspec eventually becomes a two-part source-colon-destination sequence, plus optional leading plus sign meaning force. These names do not do that.
... and if it is not a branch, what branch is it in?
I can answer the first question with
git ls-remote
Right: git ls-remote remote name
sends name
to the remote, which then not only qualifies it for you, but also tells you which hash ID that name corresponds to, in the remote repository.
but is there a way to tell what branch an object is in without at least doing a git clone --bare?
In general, no. Moreover, it may be in zero or more branches, and if the fully qualified form is a tag (refs/tags/v2.1.1
for instance) it may point to an annotated tag object, which then points to another object, which may be another annotated tag object. Eventually the annotated tag will resolve to a non-tag. You can get this, too, from git ls-remote
:
$ git ls-remote origin | grep v2.1.1
ed4f38babf3d81693a68d06cd0f5872093c009f6 refs/tags/v2.1.1
349cb5096397d9d1da33f2d046fa7e192e6214e7 refs/tags/v2.1.1^{}
but unless the target object is itself the tip commit of one or more branches, you must have enough of those objects to enumerate enough of the graph to find out whether the target object (349cb5096397d9d1da33f2d046fa7e192e6214e7
in this case):
and the general way to achieve both of these is to clone the repository.
Upvotes: 2
Reputation: 60323
If you want the history structure you'll have to fetch the history yourself or talk to some server that has access to it. There's any number of show-me-the-repo-structure servers out there, from the built-in git instaweb
to github, but they all rely on having an actual repo handy so they can show what's in it.
Upvotes: 2