0

Say that there exist a remote repo named "A", which has a submodule named "B", in a branch "Ab" ("Ab" is the branch of the "A" repo).

I do not have the A repo cloned in my machine, nor I want to clone it. I want to know the git SHA1 of the B submodule for the "Ab" branch of the A submodule, in order to git archive it.

I know the URI of A and B (it is an "ssh://.... address, if it helps).

Is that possible? How?

By the way, I do not have ssh access to the machine that has A and B repositories, so I can not do "ssh -p port destination command". The machine is a gerrit server, if it helps.

ctejeda
  • 1
  • 2

1 Answers1

1

The hash ID is embedded in the commit—or more technically, in the tree object for whatever directory contains the submodule reference. For instance, if the superproject clones the submodule at sub/mod/ule, you must read the tree for the commit, find the sub-tree named sub, read that tree and find its sub-tree named mod, read this third tree and find the entry named ule. The hash ID associated with this entry is the hash ID to be checked out in the submodule.

The only standard way to get tree objects from a Git repository without having a clone of the repository is to use git archive. However, there are only two supported archive formats (tar and zip) and for both of them, git archive writes a submodule as an empty directory, omitting the hash ID.

What this means is that the only way to read the hash ID, unless you have other software that produces it, is to clone the superproject.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thank you, @torek, but cloning the superproject is something I want to avoid, since the superproject is huge and takes a lot of time and disk space. In addition, I do not need the superproject "A" for anything. I need just "B". – ctejeda Jul 11 '18 at 09:26
  • @ctejeda: then you'll need some software on a machine that *does* have a clone of A to read that hash for you. Some hosting systems have such software (web interface for retrieving hash IDs and so on), others do not. – torek Jul 11 '18 at 13:57
  • thanks, @torek is it possible with gitweb or gerrit? – ctejeda Jul 12 '18 at 11:07
  • @ctejeda: I have no idea about gerrit. I have not used gitweb in ages but I recall there were several variants of it; you'd have to test whichever one you're using. – torek Jul 12 '18 at 17:54
  • @torek I'm late to the party, but is A still huge if you only clone branch Ab, and only its latest commit, and only the submodule itself? --branch, --depth and --fitler might let you do this. I've not tested it. If --filter doesn't help., maybe --sparse/--no-checkout (followed by a `git checkout` of selective paths) does, you still get the files downloaded to .git but not checked out into working folder. – SvenS Nov 04 '22 at 08:26
  • 1
    @SvenS: If you clone the repository with `--depth 1` and `--single-branch` (as implied by `--depth`), you'll get the one specific commit you asked for. From that commit's tree, you can find the submodule hash ID. How huge that clone might be, I have no idea; the OP simply said that they didn't want to clone it, and cloning with depth 1 is still cloning. It is indeed also probably worth investigating using the new partial clone feature to shrink the clone still further, but no matter how you slice this, it's still a *clone* – torek Nov 05 '22 at 08:06