vcstool icon indicating copy to clipboard operation
vcstool copied to clipboard

shallow clone specific hash and export

Open haudren opened this issue 3 years ago • 0 comments

In the same line as #214 , I was playing around with shallow and noticed that importing shallowly git repositories with a version specified by a hash causes errors when exporting. Again, I am using vcstool 2.15, so there is a chance this was fixed in the later versions.

Using this YAML:

repositories:
  vcstool:
    type: git
    url: [email protected]:dirk-thomas/vcstool.git
    version: 89bbf6168680a41af2367a30c8b7e42caf81cdb9

And running

vcs import --input test.yaml --shallow --skip-existing

Followed by any of the following:

vcs export
vcs export --exact
vcs export --exact-with-tags

Results in the following error:

vcstool: Could not determine remote containing '89bbf6168680a41af2367a30c8b7e42caf81cdb9'

I have narrowed down the cause to the following line: https://github.com/dirk-thomas/vcstool/blob/d12093397d5ad62403013f8642294a2788d260e9/vcstool/clients/git.py#L160

It seems that git rev-list --remotes=origin --tags does not return anything in this case as .git/refs is empty. I believe that a simple git rev-parse HEAD and git tag --points-at HEAD is enough information to deduce exact-with-tags, but I might be missing a lot of the details here as you seem to double check that the tag exists on the remote as well.

Note that there is an easy workaround:

vcs custom --git --args fetch --deepen 1

Will fetch a bit of history (including all tags) and that'll fix the command. There might be an even easier way, but that's what I've found so far.

Any advice on how to fix that in vcstool?

haudren avatar May 18 '21 01:05 haudren