{"thread":{"id":"57351","subject":"Getting rid of \"hint: Using 'master' as the name for the initial branch.\" when initializing a repository with pygit","startedAt":"2022-02-01T18:41:32Z","lastAt":"2022-02-01T20:15:55Z","messageCount":5,"participants":["Michal Suchánek","Taylor Blau"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"447442","messageId":"20220201184128.GT3113@kunlun.suse.cz","threadId":"57351","inReplyTo":null,"subject":"Getting rid of \"hint: Using 'master' as the name for the initial branch.\" when initializing a repository with pygit","fromName":"Michal Suchánek","fromEmail":"msuchanek@suse.de","sentAt":"2022-02-01T18:41:28Z","receivedAt":"2022-02-01T18:41:32Z","isPatch":false,"sender":{"key":"msuchanek@suse.de","avatar":"https://avatars.githubusercontent.com/u/787652?v=4"},"body":"Hello,\n\nI am running some tests of a project that uses pygit, and the test\ncreates a test repository .. using pygit.\n\nI noticed that in some environments the default branch warning is\ndisplayed and not others because the git version varies.\n\nThe warning is just noise in the test log so I would like to avoid it,\nand I would like to find a solution that works for git that predates the\nintroduction of this warning and the option to silence it as well as\nthe future git versions in which the default is subject to change.\n\nAFAICT there is no clean way to do it. I can set up the global option to\nwhatever but I don't want to do that just to run tests.\n\nI could set the repo local option but before calling\npygit2.init_repository() there is no repository to configure, and after\nit is too late because I expect the message to be printed by this call.\n\nAlso I cannot rely on pygit to have some latest bells and whistles\nbecause like git it varies across environments and the whole point of\nrunning the test in different environments is to verify that it works\nwith whatever tool versions are avaialble there.\n\nAny ideas?\n\nThanks\n\nMichal\n"},{"id":"447449","messageId":"YfmPiZZ/1RGzzfWE@nand.local","threadId":"57351","inReplyTo":"20220201184128.GT3113@kunlun.suse.cz","subject":"Re: Getting rid of \"hint: Using 'master' as the name for the initial branch.\" when initializing a repository with pygit","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-02-01T19:52:41Z","receivedAt":"2022-02-01T19:52:45Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Feb 01, 2022 at 07:41:28PM +0100, Michal Suchánek wrote:\n> I noticed that in some environments the default branch warning is\n> displayed and not others because the git version varies.\n>\n> The warning is just noise in the test log so I would like to avoid it,\n> and I would like to find a solution that works for git that predates the\n> introduction of this warning and the option to silence it as well as\n> the future git versions in which the default is subject to change.\n>\n> AFAICT there is no clean way to do it. I can set up the global option to\n> whatever but I don't want to do that just to run tests.\n\nIf you have set the init.defaultBranch configuration, we will suppress\nthe hint you're talking about.\n\nAlternatively, you can make sure that `git init` is invoked with the\n`-q` (quiet) flag, which suppresses that warning whether or not you have\nset the init.defaultBranch config.\n\n(Here, I'm assuming that the library you're talking about invokes the\ngit binary and respects its configuration. I'm not sure how much control\nyou have over the flags that get passed down to the git binary, though).\n\nWe could also make it possible to suppress just that advice (with\nanother advice.* configuration option), but it seems redundant with the\nexistence of the other two options I discussed above.\n\nThanks,\nTaylor\n"},{"id":"447451","messageId":"20220201195913.GV3113@kunlun.suse.cz","threadId":"57351","inReplyTo":"20220201184128.GT3113@kunlun.suse.cz","subject":"Re: Getting rid of \"hint: Using 'master' as the name for the initial branch.\" when not initializing a repository with pygit","fromName":"Michal Suchánek","fromEmail":"msuchanek@suse.de","sentAt":"2022-02-01T19:59:13Z","receivedAt":"2022-02-01T19:59:17Z","isPatch":false,"sender":{"key":"msuchanek@suse.de","avatar":"https://avatars.githubusercontent.com/u/787652?v=4"},"body":"On Tue, Feb 01, 2022 at 07:41:28PM +0100, Michal Suchánek wrote:\n> Hello,\n> \n> I am running some tests of a project that uses pygit, and the test\n> creates a test repository .. using pygit.\n> \n> I noticed that in some environments the default branch warning is\n> displayed and not others because the git version varies.\n> \n> The warning is just noise in the test log so I would like to avoid it,\n> and I would like to find a solution that works for git that predates the\n> introduction of this warning and the option to silence it as well as\n> the future git versions in which the default is subject to change.\n> \n> AFAICT there is no clean way to do it. I can set up the global option to\n> whatever but I don't want to do that just to run tests.\n> \n> I could set the repo local option but before calling\n> pygit2.init_repository() there is no repository to configure, and after\n> it is too late because I expect the message to be printed by this call.\n> \n> Also I cannot rely on pygit to have some latest bells and whistles\n> because like git it varies across environments and the whole point of\n> running the test in different environments is to verify that it works\n> with whatever tool versions are avaialble there.\n\nActually, I found that the code uses a mix of pygit2 and direct git\ncalls, and it's the direct call to git init that prints the warning\nwhich can be fixed trivially by using pygit:\n@@ -460,7 +460,7 @@ class TestMergeTool(unittest.TestCase):\n         self.ks_dir = tempfile.mkdtemp(prefix=\"gs_ks\")\n         os.chdir(self.ks_dir)\n \n-        subprocess.check_call((\"git\", \"init\", \"./\",), stdout=subprocess.DEVNULL)\n+        pygit2.init_repository(\"./\")\n         subprocess.check_call(\n             (\"git\", \"config\", \"--add\", \"mergetool.git-sort.cmd\",\n              \"%s $LOCAL $BASE $REMOTE $MERGED\" % (\n\nwhich begs the question how would I fix it if I was not using pygit. The\ngit version that does not produce the warning also does not support -b\nso it cannot be be universally used with git init. Is there some\nreasonable waey to detect this?\n\nThanks\n\nMichal\n"},{"id":"447452","messageId":"20220201200246.GW3113@kunlun.suse.cz","threadId":"57351","inReplyTo":"YfmPiZZ/1RGzzfWE@nand.local","subject":"Re: Getting rid of \"hint: Using 'master' as the name for the initial branch.\" when initializing a repository with pygit","fromName":"Michal Suchánek","fromEmail":"msuchanek@suse.de","sentAt":"2022-02-01T20:02:46Z","receivedAt":"2022-02-01T20:02:49Z","isPatch":false,"sender":{"key":"msuchanek@suse.de","avatar":"https://avatars.githubusercontent.com/u/787652?v=4"},"body":"On Tue, Feb 01, 2022 at 02:52:41PM -0500, Taylor Blau wrote:\n> On Tue, Feb 01, 2022 at 07:41:28PM +0100, Michal Suchánek wrote:\n> > I noticed that in some environments the default branch warning is\n> > displayed and not others because the git version varies.\n> >\n> > The warning is just noise in the test log so I would like to avoid it,\n> > and I would like to find a solution that works for git that predates the\n> > introduction of this warning and the option to silence it as well as\n> > the future git versions in which the default is subject to change.\n> >\n> > AFAICT there is no clean way to do it. I can set up the global option to\n> > whatever but I don't want to do that just to run tests.\n> \n> If you have set the init.defaultBranch configuration, we will suppress\n> the hint you're talking about.\n\nThat's the problem - there is no way to pass the configuration when\nusing a library to create a repository.\n\n> \n> Alternatively, you can make sure that `git init` is invoked with the\n> `-q` (quiet) flag, which suppresses that warning whether or not you have\n> set the init.defaultBranch config.\n\nYes, that is exactly the option that would do it.\n\nThanks\n\nMichal\n"},{"id":"447456","messageId":"YfmU+D7wB2ePMGTZ@nand.local","threadId":"57351","inReplyTo":"20220201200246.GW3113@kunlun.suse.cz","subject":"Re: Getting rid of \"hint: Using 'master' as the name for the initial branch.\" when initializing a repository with pygit","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-02-01T20:15:52Z","receivedAt":"2022-02-01T20:15:55Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Feb 01, 2022 at 09:02:46PM +0100, Michal Suchánek wrote:\n> On Tue, Feb 01, 2022 at 02:52:41PM -0500, Taylor Blau wrote:\n>\n> > If you have set the init.defaultBranch configuration, we will suppress\n> > the hint you're talking about.\n>\n> That's the problem - there is no way to pass the configuration when\n> using a library to create a repository.\n\nOf course; but I was suggesting that you set it in $HOME/.gitconfig, or\nin your global /etc/gitconfig.\n\n> > Alternatively, you can make sure that `git init` is invoked with the\n> > `-q` (quiet) flag, which suppresses that warning whether or not you have\n> > set the init.defaultBranch config.\n>\n> Yes, that is exactly the option that would do it.\n\nOK, I assume that this means that you can pass custom flags down to `git\ninit` via the library you're using.\n\nThanks,\nTaylor\n"}]}