git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] contrib/subtree bugfix: Can't `add` annotated tag

From
James Denholm <nod.helm@gmail.com>
Date
May 13, 2014, 04:08 UTC
Message-ID
<1399954138-2807-1-git-send-email-nod.helm@gmail.com>

cmd_add_commit() is passed FETCH_HEAD by cmd_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.0

The 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.sh, pre-existing dependency of git-subtree.

Reported-by: Kevin Cagle <kcagle@micron.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: James Denholm <nod.helm@gmail.com>
---
I felt that defining revp would be a little more self-documenting than
using $rev^0.
 contrib/subtree/git-subtree.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index dc59a91..eefd720 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -557,8 +557,9 @@ cmd_add_commit()
 		commit=$(add_squashed_msg "$rev" "$dir" |
 			 git commit-tree $tree $headp -p "$rev") || exit $?
 	else
+		revp=$(peel_committish "$rev")
 		commit=$(add_msg "$dir" "$headrev" "$rev" |
-			 git commit-tree $tree $headp -p "$rev") || exit $?
+			 git commit-tree $tree $headp -p "$revp") || exit $?
 	fi
 	git reset "$commit" || exit $?
 	
-- 
1.9.2
Next: Junio C Hamano
Message 1 of 7 in “contrib/subtree bugfix: Can't `add` annotated tag”
  1. contrib/subtree bugfix: Can't `add` annotated tagJames Denholm, May 13, 2014
  2. Junio C HamanoMay 13, 2014
  3. James DenholmMay 13, 2014
  4. Junio C HamanoMay 13, 2014
  5. James DenholmMay 14, 2014
  6. Junio C HamanoMay 14, 2014
  7. James DenholmMay 14, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.