cristibalan / braid

Simple tool to help track vendor branches in a Git repository.
http://cristibalan.github.io/braid
MIT License
457 stars 64 forks source link

braid add --tag fails for annotated tags #78

Closed tirolerstefan closed 6 years ago

tirolerstefan commented 6 years ago

(braid version 1.1.0, git version 2.16.1)

I have a test sub repo with one annotated tag "tag1":

$ git show-ref --dereference
f1248d76a08a1d53a7a9549c07d388459fb6f5ae refs/heads/master
a70a5034203235e428f0c6fb214c903668caa75c refs/tags/tag1
f1248d76a08a1d53a7a9549c07d388459fb6f5ae refs/tags/tag1^{}

When I try to add this sub repo to my parent repo, I get an error:

$ braid add -v --tag tag1 ../sub sub
Braid: Executing `git --version` in /home/stfe/prog/test/repo
Braid: Executing `git rev-parse --is-inside-work-tree` in /home/stfe/prog/test/repo
Braid: Executing `git rev-parse --show-prefix` in /home/stfe/prog/test/repo
Braid: Executing `git status` in /home/stfe/prog/test/repo
Braid: Executing `git rev-parse HEAD` in /home/stfe/prog/test/repo
Braid: Executing `git add .braids.json` in /home/stfe/prog/test/repo
Braid: Adding mirror of '../sub' tag 'tag1'.
Braid: Executing `git --version` in /home/stfe/prog/test/repo
Braid: Executing `git rev-parse --is-inside-work-tree` in /home/stfe/prog/test/repo
Braid: Executing `git rev-parse --show-prefix` in /home/stfe/prog/test/repo
Braid: Executing `git config remote.tag1/braid/sub.url` in /home/stfe/prog/test/repo
Braid: Setup: Mirror 'sub' already has a remote. Replacing it (force)
Braid: Executing `git remote rm tag1/braid/sub` in /home/stfe/prog/test/repo
Braid: Setup: Creating remote for 'sub'.
Braid: Executing `git remote add tag1/braid/sub /home/stfe/.braid/cache/.._sub` in /home/stfe/prog/test/repo
Braid: Executing `git config remote.tag1/braid/sub.url` in /home/stfe/prog/test/repo
Braid: Executing `git fetch` in /home/stfe/.braid/cache/.._sub
Braid: Executing `git fetch -n tag1/braid/sub` in /home/stfe/prog/test/repo
Braid: Executing `git rev-parse tags/tag1` in /home/stfe/.braid/cache/.._sub
Braid: Executing `git read-tree --prefix=sub/ -u a70a5034203235e428f0c6fb214c903668caa75c` in /home/stfe/prog/test/repo
Braid: Resetting to 'b804d08'.
Braid: Executing `git reset --hard b804d089d3b0b9474d7b08a23d517dcd351f3f95` in /home/stfe/prog/test/repo
Braid: Shell error: fatal: failed to unpack tree object a70a5034203235e428f0c6fb214c903668caa75c

In my opinion, the problem is a wrong "tag to commit" resolution.

Here, the ID of the tag itself (git rev-parse tags/tag1 ==> a70a5034203235e428f0c6fb214c903668caa75c) is taken instead of the commit it is pointing to (f1248d76a08a1d53a7a9549c07d388459fb6f5ae).

The correct way to get the tag-commit-id might be (for both lightweight tags and annotated tags):

$ git rev-list -1 tag1
f1248d76a08a1d53a7a9549c07d388459fb6f5ae
mattmccutchen commented 6 years ago

git read-tree is perfectly happy to dereference an annotated tag to a tree. The problem is that the annotated tag object isn't fetched into the downstream repository, so git isn't able to access it in order to dereference it. So far, Braid has just fetched all branches from the mirror cache repository into the downstream repository and assumed that will cover the requested revision.

Given that we should probably be consistent and have the revision field of the mirror object always be a commit, dereferencing the annotated tag in the context of the mirror cache repository in the mirror.tag case in determine_repository_revision is a reasonable solution. (There's no need to address the design flaw of fetching all branches versus just the requested revision right now.) Dereferencing in the branch case shouldn't be necessary but wouldn't hurt. Dereferencing a user-specified revision in validate_new_revision wouldn't hurt either for the rare case that the user makes their own annotated tag in the downstream repository referring to a commit of the subproject.

giovannisaraceno commented 6 years ago

There's a workaround or a solution? I'm unable to use braid with tags

mattmccutchen commented 6 years ago

There's a workaround or a solution? I'm unable to use braid with tags

As a workaround, you can look up the commit ID of the tag and specify it using the --revision option.

I will finish up the pull request #79 myself.

realityforge commented 6 years ago

Fix released as braid version 1.1.2.

Thanks for report and code fixes