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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux