{"thread":{"id":"62073","subject":"Possible git bug - repository remote becomes hamstrung if non-existent \"remote.<remote>.fetch\" refspec is supplied","startedAt":"2024-09-06T19:29:31Z","lastAt":"2024-09-06T19:29:31Z","messageCount":1,"participants":["Stephen Morton"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"502342","messageId":"CAH8BJxEdvk5bajz0cN+6u9B-m=6ZcufsRNUhyaJ9hiHvgEq0HA@mail.gmail.com","threadId":"62073","inReplyTo":null,"subject":"Possible git bug - repository remote becomes hamstrung if non-existent \"remote.<remote>.fetch\" refspec is supplied","fromName":"Stephen Morton","fromEmail":"stephen.c.morton@gmail.com","sentAt":"2024-09-06T19:29:18Z","receivedAt":"2024-09-06T19:29:31Z","isPatch":false,"sender":{"key":"stephen.c.morton@gmail.com","avatar":"https://gravatar.com/avatar/3b826f06cabc070cbd5d53071880caad8badc3b29e0789b510353faca59ffb7b?d=mp&s=160"},"body":"Summary:\nA git repository can become blocked from any operations relating to a\nspecific remote if there is non-wildcard \"remote.<remote>.fetch\"\nconfig value set for a ref that no longer exists on that remote.\n\n(Perhaps this is not a \"bug\" per se. I don't want to cause conflict by\nusing an inflammatory term. But it is certainly something that\neffectively \"breaks\" git operation and is not debuggable or solvable\nby your typical end-user. I'm happy to call it something else, but I\nwanted to report it.)\n\nMinimal Reproducible Example:\n\n$> git config --local --add remote.origin.fetch\n\"+refs/heads/foo/bar:refs/remotes/forks/foo/bar\"\n$> git fetch\nfatal: couldn't find remote ref refs/heads/foo/bar\nfatal: the remote end hung up unexpectedly\n\nObserve how it is not clear from the error message where the problem is at all.\n\n\"git fetch --prune\" does not fix it.\nOnce you realize what the problem is (which can take a long time), a\n\"git config --local --unset refs/remotes/forks/foo/bar\" (in the\nexample above) is the only solution I've found. And the more generic\nsolution below seems a bit unwieldy\n\nfor fetchref in $(git config --get-all \"remote.${remote}.fetch\"); do\n    ref=\"${fetchref#:*}\" # everything after the colon\n    [[ \"$ref\" =~ \\*$ ]] && continue\n    if ! git ls-remote --exit-code \"${remote}\" \"$ref\" &>/dev/null; then\n        echo \"Bad ref: $fetchref does not exist on ${remote}. Removing.\"\n        git config --local --unset \"remote.${remote}.fetch\" \"$ref\"\n    fi\ndone\n"}]}