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

[StGit PATCH 5/6] New test: conflicting push in dirty worktree

From
Karl Hasselström <kha@treskal.com>
Date
Mar 20, 2008, 00:31 UTC
Message-ID
<20080320003157.13102.10350.stgit@yoghurt>
In-Reply-To
<20080320002604.13102.53757.stgit@yoghurt>

When the result of a conflicting push can't be represented in the worktree because the worktree is dirty, the push should be aborted. Similarly, the push should be aborted if we have to do the merge in the worktree, but can't because the worktree is dirty.

Add a new test that tests for this. It currently fails, in a bad way: the contents of the pushed patch is lost.

(The test uses goto instead of push, because push doesn't use the new infrastructure yet. And old-infrastructure commands never have this bug, because they refuse to run with a dirty worktree.)

This bug was found by Erik Sandberg <mandolaerik@gmail.com>, who also came up with the minimal test case that I turned into this new test.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 t/t3000-dirty-merge.sh |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
 create mode 100755 t/t3000-dirty-merge.sh
diff --git a/t/t3000-dirty-merge.sh b/t/t3000-dirty-merge.sh
new file mode 100755
index 0000000..dd81c9e
--- /dev/null
+++ b/t/t3000-dirty-merge.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+test_description='Try a push that requires merging a file that is dirty'
+
+. ./test-lib.sh
+
+test_expect_success 'Initialize StGit stack with two patches' '
+    stg init &&
+    touch a &&
+    git add a &&
+    git commit -m a &&
+    echo 1 > a &&
+    git commit -a -m p1 &&
+    echo 2 > a &&
+    git commit -a -m p2 &&
+    stg uncommit -n 2
+'
+
+test_expect_success 'Pop one patch and update the other' '
+    stg goto p1 &&
+    echo 3 > a &&
+    stg refresh
+'
+
+test_expect_failure 'Push with dirty worktree' '
+    echo 4 > a &&
+    [ "$(echo $(stg applied))" = "p1" ] &&
+    [ "$(echo $(stg unapplied))" = "p2" ] &&
+    ! stg goto p2 &&
+    [ "$(echo $(stg applied))" = "p1" ] &&
+    [ "$(echo $(stg unapplied))" = "p2" ] &&
+    [ "$(echo $(cat a))" = "4" ]
+'
+
+test_done
Previous: Karl HasselströmNext: Karl Hasselström
Message 6 of 14 in “Two bugfixes”
  1. 0/6 Two bugfixesKarl Hasselström, Mar 20, 2008
  2. 1/6 Use a special exit code for bugsKarl Hasselström, Mar 20, 2008
  3. 2/6 Make sure patches with no parents have an empty list of parentsKarl Hasselström, Mar 20, 2008
  4. 3/6 Try uncommitting a commit with not exactly one parentKarl Hasselström, Mar 20, 2008
  5. 4/6 Make sure that we only uncommit commits with exactly one parentKarl Hasselström, Mar 20, 2008
  6. 5/6 New test: conflicting push in dirty worktreeKarl Hasselström, Mar 20, 2008
  7. 6/6 Handle failed pushes differently depending on causeKarl Hasselström, Mar 20, 2008
  8. Catalin MarinasMar 20, 2008
  9. Karl HasselströmMar 24, 2008
  10. Catalin MarinasMar 24, 2008
  11. Karl HasselströmMar 24, 2008
  12. Catalin MarinasMar 25, 2008
  13. Karl HasselströmMar 25, 2008
  14. Catalin MarinasMar 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.