git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix a couple of edge cases in autostash
@ 2013-06-13 16:06 Ramkumar Ramachandra
  2013-06-13 16:06 ` [PATCH 1/3] rebase: guard against missing files in read_basic_state() Ramkumar Ramachandra
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-13 16:06 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Hi,

I apologize for having missed these two trivial cases in the original
series.

Ramkumar Ramachandra (3):
  rebase: guard against missing files in read_basic_state()
  rebase: finish_rebase() in fast-forward rebase
  rebase: finish_rebase() in noop rebase

 git-rebase.sh               |  4 ++++
 t/t3420-rebase-autostash.sh | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)

-- 
1.8.3.1.381.gf08dd97.dirty

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

* [PATCH 1/3] rebase: guard against missing files in read_basic_state()
  2013-06-13 16:06 [PATCH 0/3] Fix a couple of edge cases in autostash Ramkumar Ramachandra
@ 2013-06-13 16:06 ` Ramkumar Ramachandra
  2013-06-13 22:29   ` Junio C Hamano
  2013-06-13 16:06 ` [PATCH 2/3] rebase: finish_rebase() in fast-forward rebase Ramkumar Ramachandra
  2013-06-13 16:06 ` [PATCH 3/3] rebase: finish_rebase() in noop rebase Ramkumar Ramachandra
  2 siblings, 1 reply; 7+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-13 16:06 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-rebase.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/git-rebase.sh b/git-rebase.sh
index d0c11a9..2122fe0 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -84,6 +84,8 @@ keep_empty=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 
 read_basic_state () {
+	test -f "$state_dir/head-name" &&
+	test -f "$state_dir/onto" &&
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
 	# We always write to orig-head, but interactive rebase used to write to
-- 
1.8.3.1.381.gf08dd97.dirty

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

* [PATCH 2/3] rebase: finish_rebase() in fast-forward rebase
  2013-06-13 16:06 [PATCH 0/3] Fix a couple of edge cases in autostash Ramkumar Ramachandra
  2013-06-13 16:06 ` [PATCH 1/3] rebase: guard against missing files in read_basic_state() Ramkumar Ramachandra
@ 2013-06-13 16:06 ` Ramkumar Ramachandra
  2013-06-13 16:06 ` [PATCH 3/3] rebase: finish_rebase() in noop rebase Ramkumar Ramachandra
  2 siblings, 0 replies; 7+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-13 16:06 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

In the following case

  $ git rebase master
  Fast-forwarded autostash-fix to master.

The autostash is not applied automatically, because this codepath
forgets to call finish_rebase().  Fix this.  Also add a test to guard
against regressions.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-rebase.sh               |  1 +
 t/t3420-rebase-autostash.sh | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/git-rebase.sh b/git-rebase.sh
index 2122fe0..154d4be 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -579,6 +579,7 @@ if test "$mb" = "$orig_head"
 then
 	say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
 	move_to_original_branch
+	finish_rebase
 	exit 0
 fi
 
diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
index 479cbb2..1bde007 100755
--- a/t/t3420-rebase-autostash.sh
+++ b/t/t3420-rebase-autostash.sh
@@ -141,6 +141,17 @@ testrebase() {
 	'
 }
 
+test_expect_success "rebase: fast-forward rebase" '
+	test_config rebase.autostash true &&
+	git reset --hard &&
+	git checkout -b behind-feature-branch feature-branch~1 &&
+	test_when_finished git branch -D behind-feature-branch &&
+	echo dirty >>file1 &&
+	git rebase feature-branch &&
+	grep dirty file1 &&
+	git checkout feature-branch
+'
+
 testrebase "" .git/rebase-apply
 testrebase " --merge" .git/rebase-merge
 testrebase " --interactive" .git/rebase-merge
-- 
1.8.3.1.381.gf08dd97.dirty

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

* [PATCH 3/3] rebase: finish_rebase() in noop rebase
  2013-06-13 16:06 [PATCH 0/3] Fix a couple of edge cases in autostash Ramkumar Ramachandra
  2013-06-13 16:06 ` [PATCH 1/3] rebase: guard against missing files in read_basic_state() Ramkumar Ramachandra
  2013-06-13 16:06 ` [PATCH 2/3] rebase: finish_rebase() in fast-forward rebase Ramkumar Ramachandra
@ 2013-06-13 16:06 ` Ramkumar Ramachandra
  2 siblings, 0 replies; 7+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-13 16:06 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

In the following case

  $ git rebase master
  Current branch autostash-fix is up to date.

the autostash is not applied automatically, because this codepath
forgets to call finish_rebase().  Fix this.  Also add a test to guard
against regressions.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-rebase.sh               |  1 +
 t/t3420-rebase-autostash.sh | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/git-rebase.sh b/git-rebase.sh
index 154d4be..2d5c2bd 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -547,6 +547,7 @@ then
 		# Lazily switch to the target branch if needed...
 		test -z "$switch_to" || git checkout "$switch_to" --
 		say "$(eval_gettext "Current branch \$branch_name is up to date.")"
+		finish_rebase
 		exit 0
 	else
 		say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
index 1bde007..90eb264 100755
--- a/t/t3420-rebase-autostash.sh
+++ b/t/t3420-rebase-autostash.sh
@@ -152,6 +152,17 @@ test_expect_success "rebase: fast-forward rebase" '
 	git checkout feature-branch
 '
 
+test_expect_success "rebase: noop rebase" '
+	test_config rebase.autostash true &&
+	git reset --hard &&
+	git checkout -b same-feature-branch feature-branch &&
+	test_when_finished git branch -D same-feature-branch &&
+	echo dirty >>file1 &&
+	git rebase feature-branch &&
+	grep dirty file1 &&
+	git checkout feature-branch
+'
+
 testrebase "" .git/rebase-apply
 testrebase " --merge" .git/rebase-merge
 testrebase " --interactive" .git/rebase-merge
-- 
1.8.3.1.381.gf08dd97.dirty

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

* Re: [PATCH 1/3] rebase: guard against missing files in read_basic_state()
  2013-06-13 16:06 ` [PATCH 1/3] rebase: guard against missing files in read_basic_state() Ramkumar Ramachandra
@ 2013-06-13 22:29   ` Junio C Hamano
  2013-06-16  5:45     ` Martin von Zweigbergk
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2013-06-13 22:29 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, Martin von Zweigbergk

Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>

This does not affect correctness; i.e. head_name=$(cat that-file)
will error out if the file is missing, right?

A more troublesome is that nobody seems to check the return value of
this function.  If head-name, onto or orig-head is missing, is that
an error condition that should make the callers of read_basic_state
stop and refuse to proceed?

The way the && cascade is used seems to indicate that, but up to the
point where it sents $verbose. If and only if head-name, onto, orig-head
and quiet can be read in state-dir, verbose in state-dir is checked
and only then $verbose is set.

Martin, this seems to be from your series around early Feburary
2011.  Do you recall why these checks are cascaded this way?
I do not offhand think of a good reason.

> ---
>  git-rebase.sh | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/git-rebase.sh b/git-rebase.sh
> index d0c11a9..2122fe0 100755
> --- a/git-rebase.sh
> +++ b/git-rebase.sh
> @@ -84,6 +84,8 @@ keep_empty=
>  test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
>  
>  read_basic_state () {
> +	test -f "$state_dir/head-name" &&
> +	test -f "$state_dir/onto" &&
>  	head_name=$(cat "$state_dir"/head-name) &&
>  	onto=$(cat "$state_dir"/onto) &&
>  	# We always write to orig-head, but interactive rebase used to write to

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

* Re: [PATCH 1/3] rebase: guard against missing files in read_basic_state()
  2013-06-13 22:29   ` Junio C Hamano
@ 2013-06-16  5:45     ` Martin von Zweigbergk
  2013-06-20 19:56       ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Martin von Zweigbergk @ 2013-06-16  5:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ramkumar Ramachandra, Git List, Martin von Zweigbergk

On Thu, Jun 13, 2013 at 3:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>
> A more troublesome is that nobody seems to check the return value of
> this function.  If head-name, onto or orig-head is missing, is that
> an error condition that should make the callers of read_basic_state
> stop and refuse to proceed?

Since we unconditionally write those three (and 'quiet'), it seems
reasonable to require all of them to be there when continuing, so I
think you're right that we should fail fast.

> The way the && cascade is used seems to indicate that, but up to the
> point where it sents $verbose. If and only if head-name, onto, orig-head
> and quiet can be read in state-dir, verbose in state-dir is checked
> and only then $verbose is set.
>
> Martin, this seems to be from your series around early Feburary
> 2011.  Do you recall why these checks are cascaded this way?
> I do not offhand think of a good reason.

Neither do I. I think the cascading after 'quiet' is just a mistake on
my part. The consequences are probably close to none, since if one of
earlier commands fail, the other files will probably not be there
either. (Not defending it; I'm happy if it gets fixed, e.g. by making
it fail fast.)

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

* Re: [PATCH 1/3] rebase: guard against missing files in read_basic_state()
  2013-06-16  5:45     ` Martin von Zweigbergk
@ 2013-06-20 19:56       ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2013-06-20 19:56 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Ramkumar Ramachandra, Git List, Martin von Zweigbergk

Martin von Zweigbergk <martinvonz@gmail.com> writes:

> On Thu, Jun 13, 2013 at 3:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>>
>> A more troublesome is that nobody seems to check the return value of
>> this function.  If head-name, onto or orig-head is missing, is that
>> an error condition that should make the callers of read_basic_state
>> stop and refuse to proceed?
>
> Since we unconditionally write those three (and 'quiet'), it seems
> reasonable to require all of them to be there when continuing, so I
> think you're right that we should fail fast.
>
>> The way the && cascade is used seems to indicate that, but up to the
>> point where it sents $verbose. If and only if head-name, onto, orig-head
>> and quiet can be read in state-dir, verbose in state-dir is checked
>> and only then $verbose is set.
>>
>> Martin, this seems to be from your series around early Feburary
>> 2011.  Do you recall why these checks are cascaded this way?
>> I do not offhand think of a good reason.
>
> Neither do I. I think the cascading after 'quiet' is just a mistake on
> my part. The consequences are probably close to none, since if one of
> earlier commands fail, the other files will probably not be there
> either. (Not defending it; I'm happy if it gets fixed, e.g. by making
> it fail fast.)

I think this is probably the right thing to do, if we want to honor
the original intention of the earlier part of && cascade.  Everything
before this new "|| die" reads from a file that should always exist
(e.g. even when not asked to be quiet, that state is not signaled by
the lack of $state_dir/quiet, but by having an empty string in it),
while everything after check optional state variable files (e.g. if
$state_dir/verbose does not exist, it is not an error, but signals
that the user did not ask us to be verbose).

Note that applying this patch _could_ uncover latent bug that was
masked by the lack of "die" here (maybe later codepath may depended
on not having orig_head at all and the only observable effect was
that in such a case, both quiet and verbose were silently ignored,
because the control did not reach the GIT_QUIET=... and verbose=t
assignments.

 git-rebase.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index d0c11a9..90506ba 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -95,7 +95,9 @@ read_basic_state () {
 	else
 		orig_head=$(cat "$state_dir"/head)
 	fi &&
-	GIT_QUIET=$(cat "$state_dir"/quiet) &&
+	GIT_QUIET=$(cat "$state_dir"/quiet) ||
+	die "failed to read basic rebase state from $state_dir"
+
 	test -f "$state_dir"/verbose && verbose=t
 	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
 	test -f "$state_dir"/strategy_opts &&

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

end of thread, other threads:[~2013-06-20 19:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-13 16:06 [PATCH 0/3] Fix a couple of edge cases in autostash Ramkumar Ramachandra
2013-06-13 16:06 ` [PATCH 1/3] rebase: guard against missing files in read_basic_state() Ramkumar Ramachandra
2013-06-13 22:29   ` Junio C Hamano
2013-06-16  5:45     ` Martin von Zweigbergk
2013-06-20 19:56       ` Junio C Hamano
2013-06-13 16:06 ` [PATCH 2/3] rebase: finish_rebase() in fast-forward rebase Ramkumar Ramachandra
2013-06-13 16:06 ` [PATCH 3/3] rebase: finish_rebase() in noop rebase Ramkumar Ramachandra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).