git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH 2/3] stg uncommit should never touch the branch head

From
Karl Hasselström <kha@treskal.com>
Date
Jul 25, 2008, 00:53 UTC
Message-ID
<20080725005300.13006.96166.stgit@yoghurt>
In-Reply-To
<20080725005154.13006.8908.stgit@yoghurt>

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 |   11 +++++++++++
 t/t1303-commit.sh   |   20 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100755 t/t1303-commit.sh
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
Previous: Karl HasselströmNext: Karl Hasselström
Message 3 of 4 in “Fix uncommit with top != head”
  1. 0/3 Fix uncommit with top != headKarl Hasselström, Jul 25, 2008
  2. 1/3 Test for exit code with command_error()Karl Hasselström, Jul 25, 2008
  3. 2/3 stg uncommit should never touch the branch headKarl Hasselström, Jul 25, 2008
  4. 3/3 Make sure that stg uncommit doesn't touch the branch headKarl Hasselström, Jul 25, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.