]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t7001: add failure test which triggers assertion
authorKristoffer Haugsbakk <code@khaugsbakk.name>
Tue, 22 Oct 2024 21:14:33 +0000 (23:14 +0200)
committerTaylor Blau <me@ttaylorr.com>
Wed, 23 Oct 2024 20:36:15 +0000 (16:36 -0400)
`git mv a/a.txt a b/` is a nonsense instruction.  Instead of failing
gracefully the command trips over itself,[1] leaving behind unfinished
work:

1. first it moves `a/a.txt` to `b/a.txt`; then
2. tries to move `a/`, including `a/a.txt`; then
3. figures out that it’s in a bad state (assertion); and finally
4. aborts.

Now you’re left with a partially-updated index.

The command should instead fail gracefully and make no changes to the
index until it knows that it can complete a sensible action.

For now just add a failing test since this has been known about for
a while.[2]

† 1: Caused by a `pos >= 0` assertion
[2]: https://lore.kernel.org/git/d1f739fe-b28e-451f-9e01-3d2e24a0fe0d@app.fastmail.com/

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
t/t7001-mv.sh

index 86258f9f4307a34b49a22d3d217ac2a82cefc560..69c9190772fcea6f20b2bf36a3c61e9bcea2c742 100755 (executable)
@@ -551,4 +551,16 @@ test_expect_success 'moving nested submodules' '
        git status
 '
 
+test_expect_failure 'nonsense mv triggers assertion failure and partially updated index' '
+       test_when_finished git reset --hard HEAD &&
+       git reset --hard HEAD &&
+       mkdir -p a &&
+       mkdir -p b &&
+       >a/a.txt &&
+       git add a/a.txt &&
+       test_must_fail git mv a/a.txt a b &&
+       git status --porcelain >actual &&
+       grep "^A[ ]*a/a.txt$" actual
+'
+
 test_done