git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH 4/5] rebase -i: work on a detached HEAD
Date: Tue, 25 Sep 2007 16:43:15 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0709251643080.28395@racer.site> (raw)
In-Reply-To: <Pine.LNX.4.64.0709251640360.28395@racer.site>


Earlier, rebase -i refused to rebase a detached HEAD.  Now it no longer
does.

Incidentally, this fixes "git gc --auto" shadowing the true exit status.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-rebase--interactive.sh    |   23 +++++++++++++++--------
 t/t3404-rebase-interactive.sh |    8 ++++++++
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 4f46a15..445a299 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -312,17 +312,20 @@ do_next () {
 	else
 		NEWHEAD=$(git rev-parse HEAD)
 	fi &&
-	message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
-	git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
-	git symbolic-ref HEAD $HEADNAME && {
+	case $HEADNAME in
+	refs/*)
+		message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
+		git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
+		git symbolic-ref HEAD $HEADNAME
+		;;
+	esac && {
 		test ! -f "$DOTEST"/verbose ||
 			git diff --stat $(cat "$DOTEST"/head)..HEAD
 	} &&
 	rm -rf "$DOTEST" &&
+	git gc --auto &&
 	warn "Successfully rebased and updated $HEADNAME."
 
-	git gc --auto
-
 	exit
 }
 
@@ -362,7 +365,11 @@ do
 
 		HEADNAME=$(cat "$DOTEST"/head-name)
 		HEAD=$(cat "$DOTEST"/head)
-		git symbolic-ref HEAD $HEADNAME &&
+		case $HEADNAME in
+		refs/*)
+			git symbolic-ref HEAD $HEADNAME
+			;;
+		esac &&
 		output git reset --hard $HEAD &&
 		rm -rf "$DOTEST"
 		exit
@@ -439,8 +446,8 @@ do
 		test -z "$ONTO" && ONTO=$UPSTREAM
 
 		: > "$DOTEST"/interactive || die "Could not mark as interactive"
-		git symbolic-ref HEAD > "$DOTEST"/head-name ||
-			die "Could not get HEAD"
+		git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
+			echo "detached HEAD" > "$DOTEST"/head-name
 
 		echo $HEAD > "$DOTEST"/head
 		echo $UPSTREAM > "$DOTEST"/upstream
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 1af73a4..f2214dd 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -309,4 +309,12 @@ test_expect_success '--continue tries to commit, even for "edit"' '
 	test $parent = $(git rev-parse HEAD^)
 '
 
+test_expect_success 'rebase a detached HEAD' '
+	grandparent=$(git rev-parse HEAD~2) &&
+	git checkout $(git rev-parse HEAD) &&
+	test_tick &&
+	FAKE_LINES="2 1" git rebase -i HEAD~2 &&
+	test $grandparent = $(git rev-parse HEAD~2)
+'
+
 test_done
-- 
1.5.3.2.1057.gf4dc1

  parent reply	other threads:[~2007-09-25 15:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-25 15:42 [PATCH 0/5] Two real fixes, two minor fixes, and a style fix Johannes Schindelin
2007-09-25 15:42 ` [PATCH 1/5] rebase -i: commit when continuing after "edit" Johannes Schindelin
2007-09-25 15:42 ` [PATCH 2/5] rebase -i: style fixes and minor cleanups Johannes Schindelin
2007-09-25 15:43 ` [PATCH 3/5] rebase -i: Fix numbers in progress report Johannes Schindelin
2007-09-25 15:43 ` Johannes Schindelin [this message]
2007-09-25 15:43 ` [PATCH 5/5] rebase -i: avoid exporting GIT_AUTHOR_* variables Johannes Schindelin
2007-09-26 10:33   ` Johannes Sixt
2007-09-26 10:51     ` Johannes Schindelin
     [not found]     ` <86zlz9smqr.fsf@lola.quinscape.zz>
2007-09-26 11:18       ` Johannes Sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0709251643080.28395@racer.site \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).