diff mbox series

[05/15] rebase: fix handling of restrict_revision

Message ID b84faa86846cba6fb3f4bfa1d4f216fbce3867eb.1576861788.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series rebase: make the default backend configurable | expand

Commit Message

Derrick Stolee via GitGitGadget Dec. 20, 2019, 5:09 p.m. UTC
From: Elijah Newren <newren@gmail.com>

restrict_revision in the original shell script was an excluded revision
range.  It is also treated that way by the am-backend.  In the
conversion from shell to C (see commit 6ab54d17be3f ("rebase -i:
implement the logic to initialize $revisions in C", 2018-08-28)), the
interactive-backend accidentally treated it as a positive revision
rather than a negated one.

This was missed as there were no tests in the testsuite that tested an
interactive rebase with fork-point behavior.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/rebase.c  |  4 ++--
 t/t3400-rebase.sh | 20 +++++++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

Comments

Junio C Hamano Dec. 20, 2019, 9:37 p.m. UTC | #1
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Elijah Newren <newren@gmail.com>
>
> restrict_revision in the original shell script was an excluded revision
> range.  It is also treated that way by the am-backend.  In the
> conversion from shell to C (see commit 6ab54d17be3f ("rebase -i:
> implement the logic to initialize $revisions in C", 2018-08-28)), the
> interactive-backend accidentally treated it as a positive revision
> rather than a negated one.
>
> This was missed as there were no tests in the testsuite that tested an
> interactive rebase with fork-point behavior.

Thanks.

> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
>  builtin/rebase.c  |  4 ++--
>  t/t3400-rebase.sh | 20 +++++++++++++++++++-
>  2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index cc8f3f008f..b320bb3a30 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -364,8 +364,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
>  
>  	argv_array_pushl(&make_script_args, "", revisions, NULL);
>  	if (opts->restrict_revision)
> -		argv_array_push(&make_script_args,
> -				oid_to_hex(&opts->restrict_revision->object.oid));
> +		argv_array_pushf(&make_script_args, "^%s",
> +				 oid_to_hex(&opts->restrict_revision->object.oid));
>  
>  	ret = sequencer_make_script(the_repository, &todo_list.buf,
>  				    make_script_args.argc, make_script_args.argv,
> diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
> index 79762b989a..71fd6396cd 100755
> --- a/t/t3400-rebase.sh
> +++ b/t/t3400-rebase.sh
> @@ -165,11 +165,29 @@ test_expect_success 'rebase works with format.useAutoBase' '
>  	git rebase master
>  '
>  
> -test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
> +test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg (--merge)' '
>  	git checkout -b default-base master &&
>  	git checkout -b default topic &&
>  	git config branch.default.remote . &&
>  	git config branch.default.merge refs/heads/default-base &&
> +	git rebase --merge &&
> +	git rev-parse --verify default-base >expect &&
> +	git rev-parse default~1 >actual &&
> +	test_cmp expect actual &&
> +	git checkout default-base &&
> +	git reset --hard HEAD^ &&
> +	git checkout default &&
> +	git rebase --merge &&
> +	git rev-parse --verify default-base >expect &&
> +	git rev-parse default~1 >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
> +	git checkout -B default-base master &&
> +	git checkout -B default topic &&
> +	git config branch.default.remote . &&
> +	git config branch.default.merge refs/heads/default-base &&
>  	git rebase &&
>  	git rev-parse --verify default-base >expect &&
>  	git rev-parse default~1 >actual &&
diff mbox series

Patch

diff --git a/builtin/rebase.c b/builtin/rebase.c
index cc8f3f008f..b320bb3a30 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -364,8 +364,8 @@  static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
 
 	argv_array_pushl(&make_script_args, "", revisions, NULL);
 	if (opts->restrict_revision)
-		argv_array_push(&make_script_args,
-				oid_to_hex(&opts->restrict_revision->object.oid));
+		argv_array_pushf(&make_script_args, "^%s",
+				 oid_to_hex(&opts->restrict_revision->object.oid));
 
 	ret = sequencer_make_script(the_repository, &todo_list.buf,
 				    make_script_args.argc, make_script_args.argv,
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 79762b989a..71fd6396cd 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -165,11 +165,29 @@  test_expect_success 'rebase works with format.useAutoBase' '
 	git rebase master
 '
 
-test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
+test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg (--merge)' '
 	git checkout -b default-base master &&
 	git checkout -b default topic &&
 	git config branch.default.remote . &&
 	git config branch.default.merge refs/heads/default-base &&
+	git rebase --merge &&
+	git rev-parse --verify default-base >expect &&
+	git rev-parse default~1 >actual &&
+	test_cmp expect actual &&
+	git checkout default-base &&
+	git reset --hard HEAD^ &&
+	git checkout default &&
+	git rebase --merge &&
+	git rev-parse --verify default-base >expect &&
+	git rev-parse default~1 >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
+	git checkout -B default-base master &&
+	git checkout -B default topic &&
+	git config branch.default.remote . &&
+	git config branch.default.merge refs/heads/default-base &&
 	git rebase &&
 	git rev-parse --verify default-base >expect &&
 	git rev-parse default~1 >actual &&