stg uncommit should never touch the branch head
authorKarl Hasselström <kha@treskal.com>
Thu, 24 Jul 2008 20:55:05 +0000 (22:55 +0200)
committerKarl Hasselström <kha@treskal.com>
Thu, 24 Jul 2008 20:55:05 +0000 (22:55 +0200)
However, currently, it will set head to top, potentially losing data
(which can always be recovered via the reflog, but still). See
https://gna.org/bugs/index.php?12043. Add a test to demonstrate the
bad behavior. (Bug discovered by Erik Sandberg
<mandolaerik@gmail.com>.)

stg commit, on the other hand, should refuse to run if top != head,
since the committed patches might otherwise be lost. Add a test to
demonstrate that this is the case.

Signed-off-by: Karl Hasselström <kha@treskal.com>
t/t1300-uncommit.sh
t/t1303-commit.sh [new file with mode: 0755]

index a657ead..d01eaaa 100755 (executable)
@@ -83,4 +83,15 @@ test_expect_success 'Uncommit a commit with not precisely one parent' '
     [ "$(echo $(stg series))" = "" ]
 '
 
+# stg uncommit should work even when top != head, and should not touch
+# the head.
+test_expect_failure 'Uncommit when top != head' '
+    stg new -m foo &&
+    git reset --hard HEAD^ &&
+    h=$(git rev-parse HEAD)
+    stg uncommit bar &&
+    test $(git rev-parse HEAD) = $h &&
+    test "$(echo $(stg series))" = "+ bar > foo"
+'
+
 test_done
diff --git a/t/t1303-commit.sh b/t/t1303-commit.sh
new file mode 100755 (executable)
index 0000000..d53b9f2
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+test_description='Test stg commit'
+. ./test-lib.sh
+
+test_expect_success 'Initialize the StGIT repository' '
+    stg init
+'
+
+# stg commit with top != head should not succeed, since the committed
+# patches are poptentially lost.
+test_expect_success 'Commit when top != head (should fail)' '
+    stg new -m foo &&
+    git reset --hard HEAD^ &&
+    h=$(git rev-parse HEAD)
+    command_error stg commit &&
+    test $(git rev-parse HEAD) = $h &&
+    test "$(echo $(stg series))" = "> foo"
+'
+
+test_done