contrib/subtree bugfix: Crash if FETCH_HEAD is tag
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 42 lines · James Denholm
cmd_add_commit()is passedFETCH_HEADbycmd_add_repository, which is then rev-parsed into an object ID. However, if the user is fetching a tag rather than a branch HEAD, such as by executing:$ git subtree add -P oldGit https://github.com/git/git.git tags/v1.8.0The object ID is a tag and is never peeled, and the git commit-tree call
(line 561) slaps us in the face because it doesn't handle tag IDs.Because peeling a committish ID doesn't do anything if it's already a commit, fix by peeling[1] the object ID before assigning it to $rev, as per the patch.
[*1*]: Via
peel_committish(), from git:git-sh-setup.shReported-by Kevin Cagle <[email protected]>Diagnosed-by Junio C Hamano <[email protected]>Signed-off-by James Denholm <[email protected]>---
NB: This bug doesn't surface when using --squash, as $rev is reassigned to the squash commit vianew_squash_commitbefore git commit-tree sees it (though for simplicity,new_squash_commitnow also sees the peeled ID).Also doesn't surface when using "git subtree merge", as git merge can handle tag objects.
On a side note, if merging a tag without --squash, git merge recognises that it's a tag and adds a note to the merge commit body. It may be worth mimicking this when using "subtree merge --squash" or "subtree add".
contrib/subtree/git-subtree.sh| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)contrib/subtree/git-subtree.sh +0
-0
contrib/subtree/git-subtree.sh cmd_add_commit() · line 544
Quoted 8 lines
contrib/subtree/git-subtree.sh +1
-1@@ -538,7 +538,7 @@ cmd_add_commit() { revs=$(git rev-parse $default --revs-only "$@") || exit $? set -- $revs - rev="$1" + rev=$(peel_committish "$1") debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $?
I know that subtree isn't exactly the most popular or exciting part of the project at the moment, but given that this is adding a subtree based on an annotated tag is a reasonably sensible operation and (to me) the fix seems reasonably trivial, could I get some eyes on this?
Regards,
James Denholm.
After a closer look, it seems the initial patch wasn't correctly sent to the list. Please disregard, I'm re-sending the patch entirely.
Regards,
James Denholm.
Quoted 59 lines · James Denholm
Quoted 42 lines · James Denholm
cmd_add_commit()is passedFETCH_HEADbycmd_add_repository, which is then rev-parsed into an object ID. However, if the user is fetching a tag rather than a branch HEAD, such as by executing:$ git subtree add -P oldGit https://github.com/git/git.git tags/v1.8.0The object ID is a tag and is never peeled, and the git commit-tree call
(line 561) slaps us in the face because it doesn't handle tag IDs.Because peeling a committish ID doesn't do anything if it's already a commit, fix by peeling[1] the object ID before assigning it to $rev, as per the patch.
[*1*]: Via
peel_committish(), from git:git-sh-setup.shReported-by Kevin Cagle <[email protected]>Diagnosed-by Junio C Hamano <[email protected]>Signed-off-by James Denholm <[email protected]>---
NB: This bug doesn't surface when using --squash, as $rev is reassigned to the squash commit vianew_squash_commitbefore git commit-tree sees it (though for simplicity,new_squash_commitnow also sees the peeled ID).Also doesn't surface when using "git subtree merge", as git merge can handle tag objects.
On a side note, if merging a tag without --squash, git merge recognises that it's a tag and adds a note to the merge commit body. It may be worth mimicking this when using "subtree merge --squash" or "subtree add".
contrib/subtree/git-subtree.sh| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)contrib/subtree/git-subtree.sh +0
-0contrib/subtree/git-subtree.sh cmd_add_commit() · line 544
Quoted 8 lines
contrib/subtree/git-subtree.sh +1
-1@@ -538,7 +538,7 @@ cmd_add_commit() { revs=$(git rev-parse $default --revs-only "$@") || exit $? set -- $revs - rev="$1" + rev=$(peel_committish "$1") debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $?I know that subtree isn't exactly the most popular or exciting part of the project at the moment, but given that this is adding a subtree based on an annotated tag is a reasonably sensible operation and (to me) the fix seems reasonably trivial, could I get some eyes on this?
Regards,
James Denholm.