git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] rebase: do not fail silently when the HEAD could not be detached

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 7, 2009, 17:20 UTC
Message-ID
<679be9321b4cf4f694917cb9eebba70376a43a0a.1234027102u.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1234027102u.git.johannes.schindelin@gmx.de>

Since 6fd2f5e(rebase: operate on a detached HEAD), rebase operates on a detached HEAD. However, it used "checkout -q" to detach the HEAD, which hid an error message when, say, an untracked file would have to be overwritten to detach the HEAD.

Instead of hiding the output of the checkout in all cases, only hide it when no error occurred.

While at it, add a test that "rebase" actually operated on a detached HEAD.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-rebase.sh     |    2 +-
 t/t3400-rebase.sh |   13 ++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 6d3eddb..1526fcb 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -434,7 +434,7 @@ fi
 
 # Detach HEAD and reset the tree
 echo "First, rewinding head to replay your work on top of it..."
-git checkout -q "$onto^0" || die "could not detach HEAD"
+error=$(git checkout "$onto" 2>&1) || die "${error}could not detach HEAD"
 git update-ref ORIG_HEAD $branch
 
 # If the $onto is a proper descendant of the tip of the branch, then
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index b7a670e..8c0c5f5 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -14,7 +14,8 @@ export GIT_AUTHOR_EMAIL
 
 test_expect_success \
     'prepare repository with topic branches' \
-    'echo First > A &&
+    'git config core.logAllRefUpdates true &&
+     echo First > A &&
      git update-index --add A &&
      git commit -m "Add A." &&
      git checkout -b my-topic-branch &&
@@ -84,4 +85,14 @@ test_expect_success 'rebase a single mode change' '
      GIT_TRACE=1 git rebase master
 '
 
+test_expect_success 'HEAD was detached during rebase' '
+     test $(git rev-parse HEAD@{1}) != $(git rev-parse modechange@{1})
+'
+
+test_expect_success 'Show verbose error when HEAD could not be detached' '
+     : > B &&
+     test_must_fail git rebase topic 2> output.err > output.out &&
+     grep "Untracked working tree file .B. would be overwritten" output.err
+'
+
 test_done
-- 
1.6.1.2.655.g3f285
Next: Junio C Hamano
Message 1 of 5 in “rebase: do not fail silently when the HEAD could not be detached”
  1. rebase: do not fail silently when the HEAD could not be detachedJohannes Schindelin, Feb 7, 2009
  2. Junio C HamanoFeb 7, 2009
  3. Björn SteinbrinkFeb 7, 2009
  4. Junio C HamanoFeb 8, 2009
  5. Johannes SchindelinFeb 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.