[1/2] t3420: never change upstream branch
diff mbox series

Message ID 20190818095349.3218-2-ben@wijen.net
State New
Headers show
Series
  • git rebase: Make sure upstream branch is left alone.
Related show

Commit Message

Ben Aug. 18, 2019, 9:53 a.m. UTC
When using `git rebase --autostash <upstream> <branch>` and
the workarea is dirty, the active branch is incorrectly reset
to the rebase <upstream> branch.

This test will check for such behavior.

Signed-off-by: Ben Wijen <ben@wijen.net>
---
 t/t3420-rebase-autostash.sh | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Junio C Hamano Aug. 19, 2019, 9:55 p.m. UTC | #1
Ben Wijen <ben@wijen.net> writes:

> When using `git rebase --autostash <upstream> <branch>` and
> the workarea is dirty, the active branch is incorrectly reset
> to the rebase <upstream> branch.
>
> This test will check for such behavior.
>
> Signed-off-by: Ben Wijen <ben@wijen.net>
> ---
>  t/t3420-rebase-autostash.sh | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
> index b8f4d03467..867e4e0b17 100755
> --- a/t/t3420-rebase-autostash.sh
> +++ b/t/t3420-rebase-autostash.sh
> @@ -306,4 +306,13 @@ test_expect_success 'branch is left alone when possible' '
>  	test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"
>  '
>  
> +test_expect_success 'never change upstream branch' '
> +	test_when_finished "git reset --hard && git branch -D upstream" &&
> +	git checkout -b upstream unrelated-onto-branch &&
> +	echo changed >file0 &&
> +	git add file0 &&
> +	git rebase --autostash upstream feature-branch &&
> +	test $(git rev-parse upstream) = $(git rev-parse unrelated-onto-branch)
> +'
> +
>  test_done

If you are going to make these into two separate commits (which I do
not necessarily recommend), introduce it as "test_expect_failure" in
step 1/2 and flip it to "test_expect_success" in step 2/2, when the
breakage is corrected.

This breakage may have happened somewhere between v2.19 and v2.20,
if my hunch is correct.  If it is easy to identify the exact point
of breakage, it may make sense to note it in the log message of 2/2
as well.  My guess is 176f5d96 ("built-in rebase --autostash: leave
the current branch alone if possible", 2018-11-07) is the plausible
candidate (iow, I suspect that the "do not detach" optimization was
made a bit too aggressively by that commit), but don't quote me on
it as this was purely done by "git log --grep -p" and not compiling
or running any tests ;-)

Thanks.
Phillip Wood Aug. 20, 2019, 8:58 a.m. UTC | #2
Hi Ben

On 18/08/2019 10:53, Ben Wijen wrote:
> When using `git rebase --autostash <upstream> <branch>` and
> the workarea is dirty, the active branch is incorrectly reset
> to the rebase <upstream> branch.
> 
> This test will check for such behavior.
> 
> Signed-off-by: Ben Wijen <ben@wijen.net>
> ---
>   t/t3420-rebase-autostash.sh | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
> index b8f4d03467..867e4e0b17 100755
> --- a/t/t3420-rebase-autostash.sh
> +++ b/t/t3420-rebase-autostash.sh
> @@ -306,4 +306,13 @@ test_expect_success 'branch is left alone when possible' '
>   	test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"
>   '
>   
> +test_expect_success 'never change upstream branch' '
> +	test_when_finished "git reset --hard && git branch -D upstream" &&
> +	git checkout -b upstream unrelated-onto-branch &&
> +	echo changed >file0 &&
> +	git add file0 &&
> +	git rebase --autostash upstream feature-branch &&
> +	test $(git rev-parse upstream) = $(git rev-parse unrelated-onto-branch)

In addition to Junio's suggestions I'd add using
	test_cmp_rev upstream unrelated-onto-branch
for the last line.

Best Wishes

Phillip

> +'
> +
>   test_done
>

Patch
diff mbox series

diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
index b8f4d03467..867e4e0b17 100755
--- a/t/t3420-rebase-autostash.sh
+++ b/t/t3420-rebase-autostash.sh
@@ -306,4 +306,13 @@  test_expect_success 'branch is left alone when possible' '
 	test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"
 '
 
+test_expect_success 'never change upstream branch' '
+	test_when_finished "git reset --hard && git branch -D upstream" &&
+	git checkout -b upstream unrelated-onto-branch &&
+	echo changed >file0 &&
+	git add file0 &&
+	git rebase --autostash upstream feature-branch &&
+	test $(git rev-parse upstream) = $(git rev-parse unrelated-onto-branch)
+'
+
 test_done