{"thread":{"id":"66799","subject":"[BUG] splitIndex with skipHash corrupts index and crashes status","startedAt":"2026-11-07T12:11:16Z","lastAt":"2026-11-08T23:42:35Z","messageCount":5,"participants":["Andy Koppe","Tanga Joris"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"557790","messageId":"20261107121119.2995843-1-andy.koppe@gmail.com","threadId":"66799","inReplyTo":null,"subject":"[BUG] splitIndex with skipHash corrupts index and crashes status","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-11-07T12:11:16Z","receivedAt":"2026-11-07T12:11:16Z","isPatch":false,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"With both core.splitIndex and index.skipHash enabled (the latter e.g.\nvia feature.manyFiles), index entries are silently lost or corrupted\nwhenever the shared index is written.\n\n  $ git init -q r && cd r\n  $ git config core.splitIndex true\n  $ touch foo bar && git add . && git commit -qm init\n  $ git config index.skipHash true\n  $ git update-index --split-index\n  $ git ls-files\n  ./\n  ./\n  $ git status --short\n  BUG: wt-status.c:585: multiple renames on the same target? how?\n  Aborted (core dumped)\n\nWithout the explicit --split-index, this happens once the shared index\nis rewritten because enough entries have changed.\n\nIn a new repository, the first git add writes a shared index, and the\nadded entry is lost straight away:\n\n  $ git init -q r && cd r\n  $ git config core.splitIndex true\n  $ git config index.skipHash true\n  $ touch foo && git add foo\n  $ git status --short\n  ?? foo\n  $ ls .git | grep index\n  index\n  sharedindex.0000000000000000000000000000000000000000\n\nNote the unexpected null OID.\n\nSeen with v2.56.0 on x86_64 Linux.\n\n"},{"id":"557816","messageId":"CAKrRMNpaBrOybe0hw_B+RTZ5GWeUASpR+sRte0OLL2x6xJba8g@mail.gmail.com","threadId":"66799","inReplyTo":"20261107121119.2995843-1-andy.koppe@gmail.com","subject":"Re: [BUG] splitIndex with skipHash corrupts index and crashes status","fromName":"Tanga Joris","fromEmail":"tangajoris@gmail.com","sentAt":"2026-11-07T21:10:36Z","receivedAt":"2026-11-07T21:10:36Z","isPatch":false,"sender":{"key":"tangajoris@gmail.com","avatar":null},"body":"Hi Andy,\n\nThank you for the bug report and the clear reproduction steps.\n\nI was able to reproduce both cases on master (fb255012ac).\n\nOn Sat, 7 Nov 2026 at 15:16, Andy Koppe <andy.koppe@gmail.com> wrote:\n>   $ ls .git | grep index\n>   index\n>   sharedindex.0000000000000000000000000000000000000000\n>\n> Note the unexpected null OID.\n\nIt seems to be caused by write_shared_index() naming the file after\nthe shared index's trailing checksum. With index.skipHash, that\nchecksum is written as zeros, so the file is named\nsharedindex.0000000000000000000000000000000000000000,\nwhich is the file you saw.\n\nThe entries disappear because the split index then records a null\nbase, and read_index_from() treats a null base as \"no shared index\"\n(read-cache.c:2381), so the entries stored in the shared index are\nlost.\n\nI'm working on a fix and would be more than happy to send it, unless\nyou are already working on one.\n\nThanks,\nTanga\n\n"},{"id":"557817","messageId":"CAHWeT-abY9_OOji+WkL3_Rpnzy0xBh3MGQCnhuUO9Wdr1hJy0Q@mail.gmail.com","threadId":"66799","inReplyTo":"CAKrRMNpaBrOybe0hw_B+RTZ5GWeUASpR+sRte0OLL2x6xJba8g@mail.gmail.com","subject":"Re: [BUG] splitIndex with skipHash corrupts index and crashes status","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-11-07T21:55:38Z","receivedAt":"2026-11-07T21:55:38Z","isPatch":false,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"On Sat, 7 Nov 2026 at 21:11, Tanga Joris wrote:\n> >   $ ls .git | grep index\n> >   index\n> >   sharedindex.0000000000000000000000000000000000000000\n> >\n> > Note the unexpected null OID.\n>\n> It seems to be caused by write_shared_index() naming the file after\n> the shared index's trailing checksum. With index.skipHash, that\n> checksum is written as zeros, so the file is named\n> sharedindex.0000000000000000000000000000000000000000,\n> which is the file you saw.\n>\n> The entries disappear because the split index then records a null\n> base, and read_index_from() treats a null base as \"no shared index\"\n> (read-cache.c:2381), so the entries stored in the shared index are\n> lost.\n>\n> I'm working on a fix and would be more than happy to send it, unless\n> you are already working on one.\n\nThank you very much for looking into this! I haven't dared wading into it.\n\nAndy\n\n"},{"id":"557818","messageId":"CAKrRMNr17jK4rT_9_oOnFrx5ukZu_Jj3tSJK+JzmGnDa1xE3ZQ@mail.gmail.com","threadId":"66799","inReplyTo":"CAHWeT-abY9_OOji+WkL3_Rpnzy0xBh3MGQCnhuUO9Wdr1hJy0Q@mail.gmail.com","subject":"Re: [BUG] splitIndex with skipHash corrupts index and crashes status","fromName":"Tanga Joris","fromEmail":"tangajoris@gmail.com","sentAt":"2026-11-07T22:24:11Z","receivedAt":"2026-11-07T22:24:11Z","isPatch":false,"sender":{"key":"tangajoris@gmail.com","avatar":null},"body":"You're welcome Andy.\n\nOn Sun, 8 Nov 2026 at 00:55, Andy Koppe <andy.koppe@gmail.com> wrote:\n> Thank you very much for looking into this! I haven't dared wading into it.\n\nThat's alright, and thanks for confirming! I'll keep you posted as I\nmake progress\non the fix.\n\nBest,\nTanga\n\n"},{"id":"557866","messageId":"20261108234235.1594316-1-tangajoris@gmail.com","threadId":"66799","inReplyTo":"20261107121119.2995843-1-andy.koppe@gmail.com","subject":"[Outreachy PATCH] read-cache: do not skip the hash of the shared index","fromName":"Tanga Joris","fromEmail":"tangajoris@gmail.com","sentAt":"2026-11-08T23:42:35Z","receivedAt":"2026-11-08T23:42:35Z","isPatch":true,"sender":{"key":"tangajoris@gmail.com","avatar":null},"body":"With core.splitIndex and index.skipHash both set, index entries are\nlost when a new shared index is written:\n\n  $ git init -q r && cd r\n  $ git config core.splitIndex true\n  $ git config index.skipHash true\n  $ touch foo && git add foo\n  $ git status --short\n  ?? foo\n\nwrite_shared_index() names the file after the shared index's trailing\nchecksum. With index.skipHash, that checksum is written as zeros. The\nsplit index then records a null base, and read_index_from() treats a\nnull base as \"no shared index\". So the entries stored in the shared\nindex are lost, and \"git status\" can die with a BUG().\n\nThis has been broken since ee1f0c242e (read-cache: add index.skipHash\nconfig option, 2023-01-06).\n\nNever skip the hash when writing the shared index. $GIT_DIR/index\nstill honors index.skipHash, because it is written on every index\nupdate. A new shared index is written much less often, so only those\nwrites pay for the hash.\n\n\"git reset\" repairs an index that is already broken.\n\nReported-by: Andy Koppe <andy.koppe@gmail.com>\nSigned-off-by: Tanga Joris <tangajoris@gmail.com>\n---\nA new shared index is only written when more than\nsplitIndex.maxPercentChange (20% by default) of the entries are not in\nit, or by \"git update-index --split-index\".\n\nEntries that the split index stores as replacements show up with an\nempty name, so \"git ls-files\" prints \"./\" for them.\n\n read-cache.c           | 16 +++++++++++-----\n t/t1700-split-index.sh | 41 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 52 insertions(+), 5 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex e40f290bb3..c48ea7b1e0 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2818,7 +2818,8 @@ enum write_extensions {\n  * rely on it.\n  */\n static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n-\t\t\t  enum write_extensions write_extensions, unsigned flags)\n+\t\t\t  enum write_extensions write_extensions, unsigned flags,\n+\t\t\t  int skip_hash)\n {\n \tuint64_t start = getnanotime();\n \tstruct hashfile *f;\n@@ -2841,8 +2842,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n \n \tf = hashfd(the_repository->hash_algo, tempfile->fd, tempfile->filename.buf);\n \n-\tprepare_repo_settings(r);\n-\tf->skip_hash = r->settings.index_skip_hash;\n+\tf->skip_hash = skip_hash;\n \n \tfor (i = removed = extended = 0; i < entries; i++) {\n \t\tif (cache[i]->ce_flags & CE_REMOVE)\n@@ -3147,9 +3147,11 @@ static int do_write_locked_index(struct index_state *istate,\n \t\treturn ret;\n \t}\n \n+\tprepare_repo_settings(istate->repo);\n \ttrace2_region_enter_printf(\"index\", \"do_write_index\", istate->repo,\n \t\t\t\t   \"%s\", get_lock_file_path(lock));\n-\tret = do_write_index(istate, lock->tempfile, write_extensions, flags);\n+\tret = do_write_index(istate, lock->tempfile, write_extensions, flags,\n+\t\t\t     istate->repo->settings.index_skip_hash);\n \ttrace2_region_leave_printf(\"index\", \"do_write_index\", istate->repo,\n \t\t\t\t   \"%s\", get_lock_file_path(lock));\n \n@@ -3262,9 +3264,13 @@ static int write_shared_index(struct index_state *istate,\n \tmove_cache_to_base_index(istate);\n \tconvert_to_sparse(istate, 0);\n \n+\t/*\n+\t * The shared index is named after its hash, and the split index\n+\t * refers to it by that hash, so never skip it here.\n+\t */\n \ttrace2_region_enter_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n-\tret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags);\n+\tret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags, 0);\n \ttrace2_region_leave_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n \ndiff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh\nindex 887e72a5fa..2517ac9eff 100755\n--- a/t/t1700-split-index.sh\n+++ b/t/t1700-split-index.sh\n@@ -544,4 +544,45 @@ test_expect_success 'GIT_TEST_SPLIT_INDEX works' '\n \t)\n '\n \n+test_expect_success 'index.skipHash does not apply to the shared index' '\n+\tgit init skip-hash-rewrite &&\n+\t(\n+\t\tcd skip-hash-rewrite &&\n+\t\tgit config core.splitIndex true &&\n+\t\t>foo &&\n+\t\t>bar &&\n+\t\tgit add foo bar &&\n+\t\tgit commit -m initial &&\n+\t\tgit config index.skipHash true &&\n+\t\tgit update-index --split-index &&\n+\t\ttest_path_is_missing .git/sharedindex.$ZERO_OID &&\n+\t\ttest_trailing_hash .git/index >hash &&\n+\t\techo $ZERO_OID >expect &&\n+\t\ttest_cmp expect hash &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tbar\n+\t\tfoo\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual &&\n+\t\tgit status --short --untracked-files=no >actual &&\n+\t\ttest_must_be_empty actual\n+\t)\n+'\n+\n+test_expect_success 'index.skipHash does not lose the first entry in split mode' '\n+\tgit init skip-hash-first-add &&\n+\t(\n+\t\tcd skip-hash-first-add &&\n+\t\tgit config core.splitIndex true &&\n+\t\tgit config index.skipHash true &&\n+\t\t>foo &&\n+\t\tgit add foo &&\n+\t\ttest_path_is_missing .git/sharedindex.$ZERO_OID &&\n+\t\techo foo >expect &&\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\n-- \n2.56.0.388.g09a996e1ff\n\n\n"}]}