Skip to content

Commit 0fcd473

Browse files
LemmingAvalanchettaylorr
authored andcommitted
t7001: add failure test which triggers assertion
`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/[email protected]/ Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Kristoffer Haugsbakk <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 34b6ce9 commit 0fcd473

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

t/t7001-mv.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,16 @@ test_expect_success 'moving nested submodules' '
551551
git status
552552
'
553553

554+
test_expect_failure 'nonsense mv triggers assertion failure and partially updated index' '
555+
test_when_finished git reset --hard HEAD &&
556+
git reset --hard HEAD &&
557+
mkdir -p a &&
558+
mkdir -p b &&
559+
>a/a.txt &&
560+
git add a/a.txt &&
561+
test_must_fail git mv a/a.txt a b &&
562+
git status --porcelain >actual &&
563+
grep "^A[ ]*a/a.txt$" actual
564+
'
565+
554566
test_done

0 commit comments

Comments
 (0)