{"thread":{"id":"59684","subject":"git merge crash \"fatal: stash failed\" with smudge/clean filters","startedAt":"2023-05-02T17:23:43Z","lastAt":"2023-05-02T17:23:43Z","messageCount":1,"participants":["Joey Hess"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"476439","messageId":"ZFFGi9i7JGL9xNx5@kitenet.net","threadId":"59684","inReplyTo":null,"subject":"git merge crash \"fatal: stash failed\" with smudge/clean filters","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2023-05-02T17:21:15Z","receivedAt":"2023-05-02T17:23:43Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"The attached testcase seems to show a bug in git. git merge crashes\nwith an internal error of \"fatal: stash failed\".\n\nThe testcase uses some very basic smudge/clean filters, and that\nis necessary to see the crash. (The filters may be kinda broken,\nthey're the first thing I tried to detangle this bug from git-annex.)\n\nThe test case first creates an empty file, and that is somehow\nsignificant. While the merge does not directly involve that empty file,\nomitting adding the empty file, or making it have any non-empty content\navoids the merge crash. And the crash happens after cleaning the empty file:\n\njoey@darkstar:~/tmp/x/testcase-workdir/repo1>GIT_PACKET_TRACE=1 GIT_TRACE=1 git merge repo2/master\n13:17:20.064936 git.c:439               trace: built-in: git merge repo2/master\n13:17:20.070120 run-command.c:655       trace: run_command: '.git/test-clean '\\''emptyfile'\\'''\n13:17:20.094653 run-command.c:655       trace: run_command: git stash create\n13:17:20.097780 git.c:439               trace: built-in: git stash create\n13:17:20.099213 run-command.c:655       trace: run_command: '.git/test-clean '\\''emptyfile'\\'''\nfatal: stash failed\n\ngit version 2.40.1.459.g48d89b51b3\n\n-- \nsee shy jo\n\n\n#!/bin/bash\nsetup_smudge_clean() {\n\tcat <<'EOF' > .git/test-clean\n#!/bin/sh\nmkdir -p ../content\ncat > ../content/new.content\nv=$(sha1sum ../content/new.content | cut -d ' ' -f 1)\nmv ../content/new.content ../content/$v.content\necho \"$v\"\nEOF\n\tcat <<'EOF' > .git/test-smudge\n#!/bin/sh\nv=$(cat)\ncat ../content/$v.content\nEOF\n\tchmod +x .git/test-clean\n\tchmod +x .git/test-smudge\n\tgit config filter.foo.smudge '.git/test-smudge %f'\n\tgit config filter.foo.clean '.git/test-clean %f'\n\techo \"* filter=foo\" > .git/info/attributes\n}\n\nmkdir testcase-workdir\ncd testcase-workdir\ngit init repo1\ncd repo1\nsetup_smudge_clean\ngit commit --allow-empty -m foo\ngit remote add repo2 ../repo2\ncd ..\ngit clone repo1 repo2\ncd repo2\ngit remote add repo1 ../repo1\nsetup_smudge_clean\ncd ..\n\ncd repo1\ntouch emptyfile\ngit add emptyfile\ngit commit -m add\ncd ../repo2\ngit pull\n\necho foo > testfile\ngit add testfile\ngit commit -m foo\ncd ../repo1\necho bar > testfile\ngit add testfile\ngit commit -m bar\ngit fetch repo2 master\ngit merge repo2/master # crashes\n"}]}