summaryrefslogtreecommitdiff
path: root/t/t7106-reset-unborn-branch.sh
diff options
context:
space:
mode:
authorMartin von Zweigbergk <martinvonz@gmail.com>2013-01-15 05:47:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-01-15 17:38:08 (GMT)
commit166ec2e96e31bac913f44823dadd6c732d353172 (patch)
tree94b6fc2265b3855a39cb890b96c6f94e0789ea67 /t/t7106-reset-unborn-branch.sh
parent2f328c3d2e88230a236e3d84d2bd6de59aea578d (diff)
downloadgit-166ec2e96e31bac913f44823dadd6c732d353172.zip
git-166ec2e96e31bac913f44823dadd6c732d353172.tar.gz
git-166ec2e96e31bac913f44823dadd6c732d353172.tar.bz2
reset: allow reset on unborn branch
Some users seem to think, knowingly or not, that being on an unborn branch is like having a commit with an empty tree checked out, but when run on an unborn branch, "git reset" currently fails with: fatal: Failed to resolve 'HEAD' as a valid ref. Instead of making users figure out that they should run git rm --cached -r . , let's teach "git reset" without a revision argument, when on an unborn branch, to behave as if the user asked to reset to an empty tree. Don't take the analogy with an empty commit too far, though, but still disallow explictly referring to HEAD in "git reset HEAD". Signed-off-by: Martin von Zweigbergk <martinvonz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t7106-reset-unborn-branch.sh')
-rwxr-xr-xt/t7106-reset-unborn-branch.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/t/t7106-reset-unborn-branch.sh b/t/t7106-reset-unborn-branch.sh
new file mode 100755
index 0000000..8062cf5
--- /dev/null
+++ b/t/t7106-reset-unborn-branch.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+test_description='git reset should work on unborn branch'
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo a >a &&
+ echo b >b
+'
+
+test_expect_success 'reset' '
+ git add a b &&
+ git reset &&
+ test "$(git ls-files)" = ""
+'
+
+test_expect_success 'reset HEAD' '
+ rm .git/index &&
+ git add a b &&
+ test_must_fail git reset HEAD
+'
+
+test_expect_success 'reset $file' '
+ rm .git/index &&
+ git add a b &&
+ git reset a &&
+ test "$(git ls-files)" = "b"
+'
+
+test_expect_success 'reset -p' '
+ rm .git/index &&
+ git add a &&
+ echo y | git reset -p &&
+ test "$(git ls-files)" = ""
+'
+
+test_expect_success 'reset --soft is a no-op' '
+ rm .git/index &&
+ git add a &&
+ git reset --soft
+ test "$(git ls-files)" = "a"
+'
+
+test_expect_success 'reset --hard' '
+ rm .git/index &&
+ git add a &&
+ git reset --hard &&
+ test "$(git ls-files)" = "" &&
+ test_path_is_missing a
+'
+
+test_done