{"thread":{"id":"59919","subject":"Bug Report","startedAt":"2023-06-27T16:03:05Z","lastAt":"2023-07-05T17:32:45Z","messageCount":5,"participants":["Tiago d'Almeida","Jeff King","Johannes Schindelin","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"478897","messageId":"CAO=RawtAvOna1xrBNY+T-fo4UQe-ipC6OvFODvOSdu4wUML3Ng@mail.gmail.com","threadId":"59919","inReplyTo":null,"subject":"Bug Report","fromName":"Tiago d'Almeida","fromEmail":"tjamadeira@gmail.com","sentAt":"2023-06-27T16:02:30Z","receivedAt":"2023-06-27T16:03:05Z","isPatch":false,"sender":{"key":"tjamadeira@gmail.com","avatar":null},"body":"Hello!\n\nI'm Tiago and sorry for any mistake because it is my first bug report to git.\n\nSo after git updated, I begin to get some errors and unexpected git\nstatus output.\n\nI made a test git repo to test this, and here are the results:\n\n```\nmkdir git_bug && cd git_bug\ngit init -q && git maintenance register && echo \"Done!\"\ntouch <files>\nmkdir <folders>\ntouch <files in folders>\ngit status --short\n\n## No commits yet on main\n?? LICENSE\n?? README.md\n?? folder/\n?? folder_1/\n\ngit add <files>\ngit status\n\n## No commits yet on main\n?? LICENSE\n?? README.md\n?? folder/\n?? folder_1/\n\ngit commit -s -m \"First commit\"\n\nOn branch main\n\nInitial commit\n\nUntracked files:\nLICENSE\nREADME.md\nfolder/\nfolder_1/\n\nnothing added to commit but untracked files present\n\n```\n\nAttached to this email follow the `git bugreport` and global `config`\nfiles, and the git_bug repo.\n\nI've checked my global config file and it seems all ok, but if there\nis some error or contradicition, please tell me.\n\nThanks in advance!\n\n\nThank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nA normal git routine.\n- git add <files>\n- git commit -s -m \"Commit\"\n\nWhat did you expect to happen? (Expected behavior)\n\nNo errors and the files being added and commited.\n\nWhat happened instead? (Actual behavior)\n\nNo files added. Error when tried to commit.\n\nWhat's different between what you expected and what actually happened?\n\nThe error.\n\nAnything else you want to add:\n\nThis just happened after updating git to version 2.41 \n\n\n[System Info]\ngit version 2.41.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 6.3.8-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 15 02:15:40 UTC 2023 x86_64\ncompiler info: gnuc: 13.1\nlibc info: glibc: 2.37\n$SHELL (typically, interactive shell): /usr/bin/fish\n\n\n[Enabled Hooks]\n"},{"id":"479005","messageId":"20230629083859.GA585934@coredump.intra.peff.net","threadId":"59919","inReplyTo":"CAO=RawtAvOna1xrBNY+T-fo4UQe-ipC6OvFODvOSdu4wUML3Ng@mail.gmail.com","subject":"index.skipHash doesn't work with split index, was Re: Bug Report","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-06-29T08:38:59Z","receivedAt":"2023-06-29T08:42:31Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jun 27, 2023 at 05:02:30PM +0100, Tiago d'Almeida wrote:\n\n> Attached to this email follow the `git bugreport` and global `config`\n> files, and the git_bug repo.\n\nThanks for providing your config; it was very important to reproducing.\nThe bug comes from the combination of \"core.splitIndex\" and\n\"index.skipHash\" (the latter is triggered in your config by\n\"feature.manyFiles\").\n\nHere's a quick reproduction:\n\n  git init repo\n  cd repo\n  touch file\n  git -c core.splitIndex=true -c index.skipHash=true add file\n\nThat should add \"file\" to the index but doesn't. Removing either the\nsplitIndex option or the skipHash option makes it work. I didn't dig\nfurther than that.\n\nAdding the author of skipHash to the cc.\n\n-Peff\n"},{"id":"479162","messageId":"20230703191636.GA3546592@coredump.intra.peff.net","threadId":"59919","inReplyTo":"UCH8XR.AR4M4C9D538Q1@gmail.com","subject":"Re: index.skipHash doesn't work with split index, was Re: Bug Report","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-07-03T19:16:36Z","receivedAt":"2023-07-03T19:17:04Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"[re-adding list to cc, so everybody can benefit from the answer]\n\nOn Mon, Jul 03, 2023 at 07:43:42PM +0100, Tiago d'Almeida wrote:\n\n> Meanwhile, just a question:\n> \n> How can I correct the corrupted git repos that are in my computer with\n> unstaged changes?\n\nProbably the best path forward is:\n\n  1. Disable one or both of the problematic config options:\n\n       git config --global core.splitIndex false\n\n  2. Blow away the old index, and have git re-populate it from the HEAD\n     commit:\n\n       rm -f .git/index\n       git reset\n\n     Usually \"git reset\" would be enough here, but since we don't know\n     what funny or possibly corrupted state the index file is in,\n     deleting it first seems wise). Because the default for git-reset is\n     \"--mixed\", this won't touch your working tree files at all.\n\n  3. You should then be able to run \"git status\" to see any differences\n     between the working tree and the fresh index (including any\n     untracked ones). And now \"git add\", etc, should work.\n\n-Peff\n"},{"id":"479198","messageId":"3b9165a7-e37e-f429-bbcb-1b95aa9731fc@gmx.de","threadId":"59919","inReplyTo":"20230629083859.GA585934@coredump.intra.peff.net","subject":"Re: index.skipHash doesn't work with split index, was Re: Bug Report","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2023-07-05T14:27:50Z","receivedAt":"2023-07-05T14:28:01Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 29 Jun 2023, Jeff King wrote:\n\n> On Tue, Jun 27, 2023 at 05:02:30PM +0100, Tiago d'Almeida wrote:\n>\n> > Attached to this email follow the `git bugreport` and global `config`\n> > files, and the git_bug repo.\n>\n> Thanks for providing your config; it was very important to reproducing.\n> The bug comes from the combination of \"core.splitIndex\" and\n> \"index.skipHash\" (the latter is triggered in your config by\n> \"feature.manyFiles\").\n>\n> Here's a quick reproduction:\n>\n>   git init repo\n>   cd repo\n>   touch file\n>   git -c core.splitIndex=true -c index.skipHash=true add file\n\nI ran into this issue while debugging the `commit -am` issue I worked on\nin https://github.com/gitgitgadget/git/pull/1554.\n\nThe reason is that `write_shared_index()` calls `do_write_index()` without\nany additional flags (see\nhttps://github.com/git/git/blob/v2.41.0/read-cache.c#L3300) and\n`do_write_index()` heeds the `index.skipHash` setting always (see\nhttps://github.com/git/git/blob/v2.41.0/read-cache.c#L2900).\n\nI briefly experimented with this diff, which is ugly and should not be\nused as is, but it seemed to fix the issue for me:\n\n-- snip --\ndiff --git a/read-cache.c b/read-cache.c\nindex ee6bcf40351..92a4aa2f25a 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -3292,14 +3294,17 @@ static int write_shared_index(struct index_state *istate,\n \t\t\t      struct tempfile **temp, unsigned flags)\n {\n \tstruct split_index *si = istate->split_index;\n-\tint ret, was_full = !istate->sparse_index;\n+\tint ret, was_full = !istate->sparse_index, saved_skip_hash;\n\n \tmove_cache_to_base_index(istate);\n \tconvert_to_sparse(istate, 0);\n\n \ttrace2_region_enter_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n+\tsaved_skip_hash = si->base->repo->settings.index_skip_hash;\n+\tsi->base->repo->settings.index_skip_hash = 0;\n \tret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags);\n+\tsi->base->repo->settings.index_skip_hash = saved_skip_hash;\n \ttrace2_region_leave_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n\n-- snap --\n\nThe reason why this is needed is that the shared index _must_ have an\nidentifer that the split index can use, and that's that index hash.\nSkipping it breaks that pattern.\n\nProbably a much better idea than above-mentioned diff would be to add a\nnew flag as a sibling to `COMMIT_LOCK` (i.e. here:\nhttps://github.com/git/git/blob/v2.41.0/cache.h#L346-L348) and use that\nonly in `write_shared_index()` to force the index hash to be computed and\nwritten.\n\nI won't have time to work on this, though.\n\nCiao,\nJohannes\n\n>\n> That should add \"file\" to the index but doesn't. Removing either the\n> splitIndex option or the skipHash option makes it work. I didn't dig\n> further than that.\n>\n> Adding the author of skipHash to the cc.\n>\n> -Peff\n>\n"},{"id":"479213","messageId":"xmqqttui1d1i.fsf@gitster.g","threadId":"59919","inReplyTo":"3b9165a7-e37e-f429-bbcb-1b95aa9731fc@gmx.de","subject":"Re: index.skipHash doesn't work with split index, was Re: Bug Report","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-05T17:30:33Z","receivedAt":"2023-07-05T17:32:45Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> The reason why this is needed is that the shared index _must_ have an\n> identifer that the split index can use, and that's that index hash.\n> Skipping it breaks that pattern.\n\nA very good summary.\n\n"}]}