{"thread":{"id":"57540","subject":"Incorrect work dir for submodule fetch operations","startedAt":"2022-03-11T14:17:21Z","lastAt":"2022-03-11T14:17:21Z","messageCount":1,"participants":["Yngve N. Pettersen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"451133","messageId":"1647006095912.1308641200.2893260369@vivaldi.com","threadId":"57540","inReplyTo":null,"subject":"Incorrect work dir for submodule fetch operations","fromName":"Yngve N. Pettersen","fromEmail":"yngve@vivaldi.com","sentAt":"2022-03-11T14:10:25Z","receivedAt":"2022-03-11T14:17:21Z","isPatch":false,"sender":{"key":"yngve@vivaldi.com","avatar":null},"body":"Hi,\nSince Git 2.21 the Windows version have frequently reported \n\n   error: cannot spawn git: Invalid argument\n\nand still do in 2.34 and 2.35.\n\nThe reported error does not seem to have any bad effects, but the error \nreport is an irritation.\n\nAt the time, this was reported to the Git for Windows team as \n<https://github.com/git-for-windows/git/issues/2126>\n\nAs it has not yet been fixed, the past couple of days I have investigated \nmore closely.\n\nThe error is printed for a submodule.c function submodule_has_commits() \nwhich starts the command \"rev-parse\" for a submodule.\n\nThe reason for the error is that the function starts the command for \nsubmodule \"foo\", which is present in the checkout directory. However, the \nactual CWD dir is the git dir for the current module, not the checkout \ndirectory, and the change directory operation therefore fails.\n\nThe \"rev-parse\" made it possible for me to connect this problem with a \ndifferent problem that I have been seeing at Linux and Mac, where the error \nmessage \n\n   fatal: exec 'rev-list': cd to 'foo' failed: No such file or directory\n\nis frequently reported, especially when a branch in the parent module has \nnew submodules defined.\n\nAFAICT, the reason for the CWD being the git dir, not the checkout dir, is \nthat  get_next_submodule() in submodule.c starts a fetch operation directly \nin the git dir, instead of the checkout directory\n\nFurther, submodule_has_commits() which is called by the fetch command via \nfetch_populated_submodules() assumes that its CWD is in the checkout \ndirectory.\n\n\nAfter a bisect it seems the regression point for this was commit \nbe76c2128234d94b47f7087152ee55d08bb65d88 \n<https://github.com/git-for-windows/git/commit/be76c2128234d94b47f7087152ee55d08bb65d88>, \nwhich added the fetch in git dir command in get_next_submodule().\n\nA testcase for reproducing the issue can be found in \n<https://github.com/git-for-windows/git/issues/2126#issuecomment-1064153093>\n (assumes default branch is \"main\"), which builds up a submodule set based \non two Chromium repos (chromium src, and depot_tools)\n\nI am uncertain what the proper fix for this issue should be, but my guess \nis that each command need to specify whether it is going to work relative \nto the git dir, or the checkout dir. It is IMO conceivable that other \ncommands may have this kind of problem, especially in a submodule context, \nor that future features may encounter them.\n\n\n\n-- \nSincerely,\nYngve N. Pettersen\nVivaldi Technologies AS\n"}]}