All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-rebase--merge: don't include absent parent as a base
@ 2016-04-20 18:20 Ben Woosley
  2016-04-20 21:13 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Woosley @ 2016-04-20 18:20 UTC (permalink / raw)
  To: git

From: Ben Woosley <ben.woosley@gmail.com>

Absent this fix, attempts to rebase an orphan branch with --strategy recursive
will fail with:

    $ git rebase ORPHAN_TARGET_BASE -s recursive
    First, rewinding head to replay your work on top of it...
    fatal: Could not parse object 'ORPHAN_ROOT_SHA^'
    Unknown exit code (128) from command: git-merge-recursive ORPHAN_ROOT_SHA^ -- HEAD ORPHAN_ROOT_SHA

To fix, this will only include the rebase root's parent as a base if it exists,
so that in cases of rebasing an orphan branch, it is a simple two-way merge.

Note the default rebase behavior does not fail:

    $ git rebase ORPHAN_TARGET_BASE
    First, rewinding head to replay your work on top of it...
    Applying: ORPHAN_ROOT_COMMIT_MSG
    Using index info to reconstruct a base tree...

Signed-off-by: Ben Woosley <ben.woosley@gmail.com>
---
 git-rebase--merge.sh    | 4 +++-
 t/t3402-rebase-merge.sh | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
index 2cc2a6d..8d43db9 100644
--- a/git-rebase--merge.sh
+++ b/git-rebase--merge.sh
@@ -67,7 +67,9 @@ call_merge () {
 		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
 	fi
 	test -z "$strategy" && strategy=recursive
-	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
+	# If cmt doesn't have a parent, don't include it as a base
+	base=$(git rev-parse --verify --quiet $cmt^)
+	eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
 	rv=$?
 	case "$rv" in
 	0)
diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh
index 8f64505..488945e 100755
--- a/t/t3402-rebase-merge.sh
+++ b/t/t3402-rebase-merge.sh
@@ -85,6 +85,15 @@ test_expect_success 'rebase -Xtheirs' '
 	! grep 11 original
 '
 
+test_expect_success 'rebase -Xtheirs from orphan' '
+	git checkout --orphan orphan-conflicting master~2 &&
+	echo "AB $T" >> original &&
+	git commit -morphan-conflicting original &&
+	git rebase -Xtheirs master &&
+	grep AB original &&
+	! grep 11 original
+'
+
 test_expect_success 'merge and rebase should match' '
 	git diff-tree -r test-rebase test-merge >difference &&
 	if test -s difference

--
https://github.com/git/git/pull/228

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] git-rebase--merge: don't include absent parent as a base
  2016-04-20 18:20 [PATCH] git-rebase--merge: don't include absent parent as a base Ben Woosley
@ 2016-04-20 21:13 ` Junio C Hamano
  2016-04-20 21:19   ` Ben Woosley
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2016-04-20 21:13 UTC (permalink / raw)
  To: Ben Woosley; +Cc: git

Ben Woosley <Ben.Woosley@gmail.com> writes:

> From: Ben Woosley <ben.woosley@gmail.com>
>
> Absent this fix, attempts to rebase an orphan branch with --strategy recursive
> will fail with:
>
>     $ git rebase ORPHAN_TARGET_BASE -s recursive
>     First, rewinding head to replay your work on top of it...
>     fatal: Could not parse object 'ORPHAN_ROOT_SHA^'
>     Unknown exit code (128) from command: git-merge-recursive ORPHAN_ROOT_SHA^ -- HEAD ORPHAN_ROOT_SHA
>
> To fix, this will only include the rebase root's parent as a base if it exists,
> so that in cases of rebasing an orphan branch, it is a simple two-way merge.
>
> Note the default rebase behavior does not fail:
>
>     $ git rebase ORPHAN_TARGET_BASE
>     First, rewinding head to replay your work on top of it...
>     Applying: ORPHAN_ROOT_COMMIT_MSG
>     Using index info to reconstruct a base tree...
>
> Signed-off-by: Ben Woosley <ben.woosley@gmail.com>
> ---
>  git-rebase--merge.sh    | 4 +++-
>  t/t3402-rebase-merge.sh | 9 +++++++++
>  2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
> index 2cc2a6d..8d43db9 100644
> --- a/git-rebase--merge.sh
> +++ b/git-rebase--merge.sh
> @@ -67,7 +67,9 @@ call_merge () {
>  		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
>  	fi
>  	test -z "$strategy" && strategy=recursive
> -	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
> +	# If cmt doesn't have a parent, don't include it as a base
> +	base=$(git rev-parse --verify --quiet $cmt^)
> +	eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'

Makes sense to me.  It is not clear if such a merge without common
ancestor is all that useful, but as it is mechanically possible,
I do not see a reason to forbid it.

>  	rv=$?
>  	case "$rv" in
>  	0)
> diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh
> index 8f64505..488945e 100755
> --- a/t/t3402-rebase-merge.sh
> +++ b/t/t3402-rebase-merge.sh
> @@ -85,6 +85,15 @@ test_expect_success 'rebase -Xtheirs' '
>  	! grep 11 original
>  '
>  
> +test_expect_success 'rebase -Xtheirs from orphan' '
> +	git checkout --orphan orphan-conflicting master~2 &&
> +	echo "AB $T" >> original &&
> +	git commit -morphan-conflicting original &&
> +	git rebase -Xtheirs master &&
> +	grep AB original &&
> +	! grep 11 original
> +'
> +
>  test_expect_success 'merge and rebase should match' '
>  	git diff-tree -r test-rebase test-merge >difference &&
>  	if test -s difference
>
> --
> https://github.com/git/git/pull/228

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] git-rebase--merge: don't include absent parent as a base
  2016-04-20 21:13 ` Junio C Hamano
@ 2016-04-20 21:19   ` Ben Woosley
  0 siblings, 0 replies; 3+ messages in thread
From: Ben Woosley @ 2016-04-20 21:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Users

It's helpful in the case where a bit of code has been detached from
its history by way of copying the files and starting a new repo, where
development continues. If you want to reunite the new history with the
prior history, while preferring the new history, you need to `rebase
-Xtheirs` the new branch onto the old.

Best,
Ben

On Wed, Apr 20, 2016 at 2:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ben Woosley <Ben.Woosley@gmail.com> writes:
>
>> From: Ben Woosley <ben.woosley@gmail.com>
>>
>> Absent this fix, attempts to rebase an orphan branch with --strategy recursive
>> will fail with:
>>
>>     $ git rebase ORPHAN_TARGET_BASE -s recursive
>>     First, rewinding head to replay your work on top of it...
>>     fatal: Could not parse object 'ORPHAN_ROOT_SHA^'
>>     Unknown exit code (128) from command: git-merge-recursive ORPHAN_ROOT_SHA^ -- HEAD ORPHAN_ROOT_SHA
>>
>> To fix, this will only include the rebase root's parent as a base if it exists,
>> so that in cases of rebasing an orphan branch, it is a simple two-way merge.
>>
>> Note the default rebase behavior does not fail:
>>
>>     $ git rebase ORPHAN_TARGET_BASE
>>     First, rewinding head to replay your work on top of it...
>>     Applying: ORPHAN_ROOT_COMMIT_MSG
>>     Using index info to reconstruct a base tree...
>>
>> Signed-off-by: Ben Woosley <ben.woosley@gmail.com>
>> ---
>>  git-rebase--merge.sh    | 4 +++-
>>  t/t3402-rebase-merge.sh | 9 +++++++++
>>  2 files changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
>> index 2cc2a6d..8d43db9 100644
>> --- a/git-rebase--merge.sh
>> +++ b/git-rebase--merge.sh
>> @@ -67,7 +67,9 @@ call_merge () {
>>               GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
>>       fi
>>       test -z "$strategy" && strategy=recursive
>> -     eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
>> +     # If cmt doesn't have a parent, don't include it as a base
>> +     base=$(git rev-parse --verify --quiet $cmt^)
>> +     eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
>
> Makes sense to me.  It is not clear if such a merge without common
> ancestor is all that useful, but as it is mechanically possible,
> I do not see a reason to forbid it.
>
>>       rv=$?
>>       case "$rv" in
>>       0)
>> diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh
>> index 8f64505..488945e 100755
>> --- a/t/t3402-rebase-merge.sh
>> +++ b/t/t3402-rebase-merge.sh
>> @@ -85,6 +85,15 @@ test_expect_success 'rebase -Xtheirs' '
>>       ! grep 11 original
>>  '
>>
>> +test_expect_success 'rebase -Xtheirs from orphan' '
>> +     git checkout --orphan orphan-conflicting master~2 &&
>> +     echo "AB $T" >> original &&
>> +     git commit -morphan-conflicting original &&
>> +     git rebase -Xtheirs master &&
>> +     grep AB original &&
>> +     ! grep 11 original
>> +'
>> +
>>  test_expect_success 'merge and rebase should match' '
>>       git diff-tree -r test-rebase test-merge >difference &&
>>       if test -s difference
>>
>> --
>> https://github.com/git/git/pull/228

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-20 21:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-20 18:20 [PATCH] git-rebase--merge: don't include absent parent as a base Ben Woosley
2016-04-20 21:13 ` Junio C Hamano
2016-04-20 21:19   ` Ben Woosley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.