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>
[ "$(echo $(stg series))" = "" ]
'
[ "$(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"
+'
+
--- /dev/null
+#!/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