# [PATCH] contrib/subtree: unwrap tag refs

5 messages from 2015-11-13 to 2016-01-13. Participants: Rob Mayoff, David A. Greene, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/40788

## Rob Mayoff, 2015-11-13 04:15

Subject: [PATCH] contrib/subtree: unwrap tag refs
Message-ID: <1447388144-23806-1-git-send-email-git@rob.dqd.com>
URL: https://gitlist.dev/e/1447388144-23806-1-git-send-email-git%40rob.dqd.com

```
From: Rob Mayoff <mayoff@dqd.com>

If a subtree was added using a tag ref, the tag ref is stored in
the subtree commit message instead of the underlying commit's ref.
To split or push subsequent changes to the subtree, the subtree
command needs to unwrap the tag ref.  This patch makes it do so.

The problem was described in a message to the mailing list from
Junio C Hamano dated 29 Apr 2014, with the subject "Re: git subtree
issue in more recent versions". The archived message can be found
at <http://comments.gmane.org/gmane.comp.version-control.git/247503>.

Signed-off-by: Rob Mayoff <mayoff@dqd.com>
---
 contrib/subtree/git-subtree.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 9f06571..b051600 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -245,7 +245,10 @@ find_latest_squash()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"
+				;;
 			END)
 				if [ -n "$sub" ]; then
 					if [ -n "$main" ]; then
@@ -278,7 +281,10 @@ find_existing_splits()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"
+				;;
 			END)
 				debug "  Main is: '$main'"
 				if [ -z "$main" -a -n "$sub" ]; then
-- 
2.4.3

```

## David A. Greene, 2015-11-13 04:36

Subject: Re: [PATCH] contrib/subtree: unwrap tag refs
Message-ID: <87h9kqwm67.fsf@waller.obbligato.org>
URL: https://gitlist.dev/e/87h9kqwm67.fsf%40waller.obbligato.org
In-Reply-To: <1447388144-23806-1-git-send-email-git@rob.dqd.com>

```
Rob Mayoff <mayoff@dqd.com> writes:

> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 9f06571..b051600 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -245,7 +245,10 @@ find_latest_squash()
>  		case "$a" in
>  			START) sq="$b" ;;
>  			git-subtree-mainline:) main="$b" ;;
> -			git-subtree-split:) sub="$b" ;;
> +			git-subtree-split:)
> +				sub="$b"

Why include the above line?

> +				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"

This seems like odd quoting.  Would not this do the same?

				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"

Perhaps I am missing something.

> +				;;
>  			END)
>  				if [ -n "$sub" ]; then
>  					if [ -n "$main" ]; then
> @@ -278,7 +281,10 @@ find_existing_splits()
>  		case "$a" in
>  			START) sq="$b" ;;
>  			git-subtree-mainline:) main="$b" ;;
> -			git-subtree-split:) sub="$b" ;;
> +			git-subtree-split:)
> +				sub="$b"

And here too.

> +				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"

Same as above.

                        -David

```

## Jeff King, 2015-11-13 05:01

Subject: Re: [PATCH] contrib/subtree: unwrap tag refs
Message-ID: <20151113050123.GA29708@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20151113050123.GA29708%40sigill.intra.peff.net
In-Reply-To: <87h9kqwm67.fsf@waller.obbligato.org>

```
On Thu, Nov 12, 2015 at 10:36:16PM -0600, David A. Greene wrote:

> > +				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"
> 
> This seems like odd quoting.  Would not this do the same?
> 
> 				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"
> 
> Perhaps I am missing something.

The former is quoting "$b" against whitespace splitting in the
sub-command. Given that the value just came from a "read" call, I think
by definition it cannot contains IFS. Still, quoting here is a good
habit.

It is actually the _outer_ quotes that are unnecessary, as variable
assignment does not do extra splitting. So:

  foo=$(echo one two)

will put the full "one two" into $foo. But the quotes do not hurt
anything, and it is a reasonable style to use them to avoid this
discussion. :)

It also matches style-wise with nearby assignments, like:

  main="$b"

-Peff

```

## David A. Greene, 2016-01-13 02:35

Subject: Re: [PATCH] contrib/subtree: unwrap tag refs
Message-ID: <87d1t6p5ov.fsf@waller.obbligato.org>
URL: https://gitlist.dev/e/87d1t6p5ov.fsf%40waller.obbligato.org
In-Reply-To: <87h9kqwm67.fsf@waller.obbligato.org>

```
I am sorry I neglected to follow-up on this.

greened@obbligato.org (David A. Greene) writes:

> Rob Mayoff <mayoff@dqd.com> writes:
>
>> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
>> index 9f06571..b051600 100755
>> --- a/contrib/subtree/git-subtree.sh
>> +++ b/contrib/subtree/git-subtree.sh
>> @@ -245,7 +245,10 @@ find_latest_squash()
>>  		case "$a" in
>>  			START) sq="$b" ;;
>>  			git-subtree-mainline:) main="$b" ;;
>> -			git-subtree-split:) sub="$b" ;;
>> +			git-subtree-split:)
>> +				sub="$b"
>
> Why include the above line?

My bad.  Missed the diff markers.  This is fine.

>> +				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"
>
> This seems like odd quoting.  Would not this do the same?
>
> 				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"
>
> Perhaps I am missing something.

Jeff explained it, so this is ok.

This all looks good to me.  Junio, please apply.

                            -David

```

## Junio C Hamano, 2016-01-13 17:40

Subject: Re: [PATCH] contrib/subtree: unwrap tag refs
Message-ID: <xmqq8u3tpedq.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq8u3tpedq.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <87d1t6p5ov.fsf@waller.obbligato.org>

```
greened@obbligato.org (David A. Greene) writes:

> I am sorry I neglected to follow-up on this.
>
> greened@obbligato.org (David A. Greene) writes:
>
>> Rob Mayoff <mayoff@dqd.com> writes:
>>
>>> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
>>> index 9f06571..b051600 100755
>>> --- a/contrib/subtree/git-subtree.sh
>>> +++ b/contrib/subtree/git-subtree.sh
>>> @@ -245,7 +245,10 @@ find_latest_squash()
>>>  		case "$a" in
>>>  			START) sq="$b" ;;
>>>  			git-subtree-mainline:) main="$b" ;;
>>> -			git-subtree-split:) sub="$b" ;;
>>> +			git-subtree-split:)
>>> +				sub="$b"
>>
>> Why include the above line?
>
> My bad.  Missed the diff markers.  This is fine.
>
>>> +				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"
>>
>> This seems like odd quoting.  Would not this do the same?
>>
>> 				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"
>>
>> Perhaps I am missing something.
>
> Jeff explained it, so this is ok.
>
> This all looks good to me.  Junio, please apply.
>
>                             -David

Thanks, all.  Let's mark rm/subtree-unwrap-tags topic to be merged
to 'next', then.

```
