{"thread":{"id":"62358","subject":"CI behaving differently from local tests","startedAt":"2024-10-17T20:47:01Z","lastAt":"2024-10-18T22:34:12Z","messageCount":2,"participants":["Bence Ferdinandy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"505390","messageId":"D4YDINQ682QL.N0FD2J9C1O22@ferdinandy.com","threadId":"62358","inReplyTo":null,"subject":"CI behaving differently from local tests","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2024-10-17T20:45:58Z","receivedAt":"2024-10-17T20:47:01Z","isPatch":false,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"Hi,\n\nI'm looking at why the set-head series (cf.:\nhttps://lore.kernel.org/git/20241014225431.1394565-1-bence@ferdinandy.com/)\nbreaks the CI. The problem stems from the local test repositories being set up\ndifferently from that of the CI.\n\nI ran both the CI and a local test on current master with the following patch\napplied on top, i.e. I print all remote refs and intentionally break the test\nso that the result is easy to get from the CI:\n\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nindex 532035933f..d625a3a8b6 100755\n--- a/t/t5505-remote.sh\n+++ b/t/t5505-remote.sh\n@@ -724,8 +724,11 @@ test_expect_success 'update' '\n \t\tcd one &&\n \t\tgit remote add drosophila ../two &&\n \t\tgit remote add apis ../mirror &&\n+\t\tgit ls-remote drosophila &&\n+\t\tgit ls-remote apis &&\n \t\tgit remote update &&\n \t\tgit branch -r >output &&\n+\t\techo \"force error\" >output &&\n \t\ttest_cmp expect output\n \t)\n '\n\nThe CI gives the following output:\nhttps://github.com/ferdinandyb/git/actions/runs/11392309625/job/31698105287\n\n\n    + git ls-remote drosophila\n    9d34b142e42f6b3dbab46dd4b9bc515e0ab16101       HEAD\n    9d34b142e42f6b3dbab46dd4b9bc515e0ab16101       refs/heads/another\n    9d34b142e42f6b3dbab46dd4b9bc515e0ab16101       refs/heads/main\n    2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f       refs/heads/side\n    + git ls-remote apis\n    6329a3ca5268a0b28a1dc29b602e8b72a0bc1b37       HEAD\n    6329a3ca5268a0b28a1dc29b602e8b72a0bc1b37       refs/heads/main\n    2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f       refs/heads/side\n\n\nWhile from ./t5505-remote.sh -v I get:\n\n    9d34b142e42f6b3dbab46dd4b9bc515e0ab16101        HEAD\n    9d34b142e42f6b3dbab46dd4b9bc515e0ab16101        refs/heads/another\n    9d34b142e42f6b3dbab46dd4b9bc515e0ab16101        refs/heads/main\n    2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f        refs/heads/side\n    6329a3ca5268a0b28a1dc29b602e8b72a0bc1b37        refs/heads/main\n    2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f        refs/heads/side\n\nSince `git remote update` here is essentially running `git fetch --multiple --all`,\nwith the set-head series applied we're attempting to set HEAD for both\nremotes. Obviously, this fails locally and succeeds in the CI, which is\nactually the patch series behaving as intended, but obviously a drift between\nthe local and the CI testing environments.\n\nI'm probably too tired right now, but I don't see how or what could make the\nmirror repo be different depending on having it locally or in the CI ... At\nleast I know it's definitely not my patch series :) Does anyone have an idea\nwhat to try and look into?\n\nI guess ideally the fix for this would be added to the beginning of the series\nso we can continue with both local and CI tests working. (Although it could be\nmarked as a know breakage as well, not so elegant).\n\nThanks,\nBence\n\n\n-- \nbence.ferdinandy.com\n\n"},{"id":"505478","messageId":"D4ZAELFWJMKN.S88LJ6YK31LZ@ferdinandy.com","threadId":"62358","inReplyTo":"D4YDINQ682QL.N0FD2J9C1O22@ferdinandy.com","subject":"Re: CI behaving differently from local tests","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2024-10-18T22:32:17Z","receivedAt":"2024-10-18T22:34:12Z","isPatch":false,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"\nOn Thu Oct 17, 2024 at 22:45, Bence Ferdinandy <bence@ferdinandy.com> wrote:\n> Hi,\n>\n> I'm looking at why the set-head series (cf.:\n> https://lore.kernel.org/git/20241014225431.1394565-1-bence@ferdinandy.com/)\n> breaks the CI. The problem stems from the local test repositories being set up\n> differently from that of the CI.\n>\n> I ran both the CI and a local test on current master with the following patch\n> applied on top, i.e. I print all remote refs and intentionally break the test\n> so that the result is easy to get from the CI:\n>\n> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\n> index 532035933f..d625a3a8b6 100755\n> --- a/t/t5505-remote.sh\n> +++ b/t/t5505-remote.sh\n> @@ -724,8 +724,11 @@ test_expect_success 'update' '\n>  \t\tcd one &&\n>  \t\tgit remote add drosophila ../two &&\n>  \t\tgit remote add apis ../mirror &&\n> +\t\tgit ls-remote drosophila &&\n> +\t\tgit ls-remote apis &&\n>  \t\tgit remote update &&\n>  \t\tgit branch -r >output &&\n> +\t\techo \"force error\" >output &&\n>  \t\ttest_cmp expect output\n>  \t)\n>  '\n>\n> The CI gives the following output:\n> https://github.com/ferdinandyb/git/actions/runs/11392309625/job/31698105287\n>\n>\n>     + git ls-remote drosophila\n>     9d34b142e42f6b3dbab46dd4b9bc515e0ab16101       HEAD\n>     9d34b142e42f6b3dbab46dd4b9bc515e0ab16101       refs/heads/another\n>     9d34b142e42f6b3dbab46dd4b9bc515e0ab16101       refs/heads/main\n>     2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f       refs/heads/side\n>     + git ls-remote apis\n>     6329a3ca5268a0b28a1dc29b602e8b72a0bc1b37       HEAD\n>     6329a3ca5268a0b28a1dc29b602e8b72a0bc1b37       refs/heads/main\n>     2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f       refs/heads/side\n>\n>\n> While from ./t5505-remote.sh -v I get:\n>\n>     9d34b142e42f6b3dbab46dd4b9bc515e0ab16101        HEAD\n>     9d34b142e42f6b3dbab46dd4b9bc515e0ab16101        refs/heads/another\n>     9d34b142e42f6b3dbab46dd4b9bc515e0ab16101        refs/heads/main\n>     2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f        refs/heads/side\n>     6329a3ca5268a0b28a1dc29b602e8b72a0bc1b37        refs/heads/main\n>     2ce9c504874e3f0ce77f83c0bb0b1024c7a6387f        refs/heads/side\n>\n> Since `git remote update` here is essentially running `git fetch --multiple --all`,\n> with the set-head series applied we're attempting to set HEAD for both\n> remotes. Obviously, this fails locally and succeeds in the CI, which is\n> actually the patch series behaving as intended, but obviously a drift between\n> the local and the CI testing environments.\n>\n> I'm probably too tired right now, but I don't see how or what could make the\n> mirror repo be different depending on having it locally or in the CI ... At\n> least I know it's definitely not my patch series :) Does anyone have an idea\n> what to try and look into?\n>\n> I guess ideally the fix for this would be added to the beginning of the series\n> so we can continue with both local and CI tests working. (Although it could be\n> marked as a know breakage as well, not so elegant).\n>\n> Thanks,\n> Bence\n\nI found the issue. It comes down to the CI running with\n\nexport GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n\nwhile this not being set in ./t5505-remote.sh.\n\nNow the bandaid here is adding this to t5505, but it may not be the solution.\nThe problem essentially is that `git remote add --mirror -f origin [somerepo]`\ndoes not update HEAD in a bare repository.\n\nConsider the following:\n\tgit config --global init.defaultBranch mypreference\n\tmkdir one\n\tcd one\n\tgit init -b notmypreference\n\tgit commit -m \"initial commit\" --allow-empty\n\tcd ..\n\tmkdir mirror\n\tcd mirror\n\tgit init --bare\n\tgit remote add --mirror -f origin ../one\n\tcat HEAD\n\nYou'll see HEAD is ref: refs/heads/mypreference.\n\nContinuing\n\tcd ..\n\tmkdir r_one\n\tcd r_one\n\tgit init\n\tgit remote add origin ../mirror\n\tgit ls-remote\n\nWe arrive at a single reference pointing to refs/heads/notmypreference.\n\nIf we do the same exercise, but instead setting up repo \"one\" with `git init -b mypreference` \nrunning ls-remote \"r_one\" will actually also yield a HEAD reference.\n\nI'm not sure if it should or not, so for now I'll just make sure that\n./t5505-remote.sh uses \"main\" as the default branch.\n\nBest,\nBence\n\n-- \nbence.ferdinandy.com\n\n"}]}