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

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

From
Junio C Hamano <gitster@pobox.com>
Date
May 8, 2014, 17:38 UTC
Message-ID
<xmqqoaz841d3.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1399511079-1994-1-git-send-email-nod.helm@gmail.com>
James Denholm <nod.helm@gmail.com> writes:
Show 8 quoted lines
> 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.

The "rev" (not "revs") seems to be used by more things than the final commit-tree state. Are we losing some useful information by peeling it too early like this patch does? The reason why we stopped peeling when writing FETCH_HEAD was because we wanted to record the fact that we merged a tag (and use the GPG signature if found in it) when constructing the log message for the merge, and peeling the tag too early and recording the commit in FETCH_HEAD would make it impossible to do, and I am wondering if this change is making the same kind of mistake here.

I see that add_msg does not use anything useful from latest_new, so with the current state of the code, it does not make that much difference (except that it says "from commit '$latest_new'", and by peeling, the fact that the user wanted to use a tag is lost from the result).

> 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".

Yes, and this change makes such a change harder to implement on top, I suspect.

Would it be sufficient to do
	git commit-tree $tree $headp -p "$rev^0"
in that "not squashing" codepath instead?
Show 16 quoted lines
>  contrib/subtree/git-subtree.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index dc59a91..9453dae 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -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 $?
Previous: James DenholmNext: James Denholm
Message 2 of 4 in “contrib/subtree bugfix: Can't `add` annotated tag”
  1. contrib/subtree bugfix: Can't `add` annotated tagJames Denholm, May 8, 2014
  2. Junio C HamanoMay 8, 2014
  3. James DenholmMay 9, 2014
  4. James DenholmMay 12, 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.