From: Karl Hasselström Date: Thu, 24 Jul 2008 20:55:05 +0000 (+0200) Subject: stg uncommit should never touch the branch head X-Git-Tag: v0.15-rc1~197 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/9beaff2e911c0a7c07b288bfdec7597a5cefa7dd stg uncommit should never touch the branch head 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 .) 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 --- diff --git a/t/t1300-uncommit.sh b/t/t1300-uncommit.sh index a657ead..d01eaaa 100755 --- a/t/t1300-uncommit.sh +++ b/t/t1300-uncommit.sh @@ -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 index 0000000..d53b9f2 --- /dev/null +++ b/t/t1303-commit.sh @@ -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