git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Getting rid of "hint: Using 'master' as the name for the initial branch." when initializing a repository with pygit
@ 2022-02-01 18:41 Michal Suchánek
  2022-02-01 19:52 ` Taylor Blau
  2022-02-01 19:59 ` Getting rid of "hint: Using 'master' as the name for the initial branch." when not " Michal Suchánek
  0 siblings, 2 replies; 5+ messages in thread
From: Michal Suchánek @ 2022-02-01 18:41 UTC (permalink / raw)
  To: git

Hello,

I am running some tests of a project that uses pygit, and the test
creates a test repository .. using pygit.

I noticed that in some environments the default branch warning is
displayed and not others because the git version varies.

The warning is just noise in the test log so I would like to avoid it,
and I would like to find a solution that works for git that predates the
introduction of this warning and the option to silence it as well as
the future git versions in which the default is subject to change.

AFAICT there is no clean way to do it. I can set up the global option to
whatever but I don't want to do that just to run tests.

I could set the repo local option but before calling
pygit2.init_repository() there is no repository to configure, and after
it is too late because I expect the message to be printed by this call.

Also I cannot rely on pygit to have some latest bells and whistles
because like git it varies across environments and the whole point of
running the test in different environments is to verify that it works
with whatever tool versions are avaialble there.

Any ideas?

Thanks

Michal

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Getting rid of "hint: Using 'master' as the name for the initial branch." when initializing a repository with pygit
  2022-02-01 18:41 Getting rid of "hint: Using 'master' as the name for the initial branch." when initializing a repository with pygit Michal Suchánek
@ 2022-02-01 19:52 ` Taylor Blau
  2022-02-01 20:02   ` Michal Suchánek
  2022-02-01 19:59 ` Getting rid of "hint: Using 'master' as the name for the initial branch." when not " Michal Suchánek
  1 sibling, 1 reply; 5+ messages in thread
From: Taylor Blau @ 2022-02-01 19:52 UTC (permalink / raw)
  To: Michal Suchánek; +Cc: git

On Tue, Feb 01, 2022 at 07:41:28PM +0100, Michal Suchánek wrote:
> I noticed that in some environments the default branch warning is
> displayed and not others because the git version varies.
>
> The warning is just noise in the test log so I would like to avoid it,
> and I would like to find a solution that works for git that predates the
> introduction of this warning and the option to silence it as well as
> the future git versions in which the default is subject to change.
>
> AFAICT there is no clean way to do it. I can set up the global option to
> whatever but I don't want to do that just to run tests.

If you have set the init.defaultBranch configuration, we will suppress
the hint you're talking about.

Alternatively, you can make sure that `git init` is invoked with the
`-q` (quiet) flag, which suppresses that warning whether or not you have
set the init.defaultBranch config.

(Here, I'm assuming that the library you're talking about invokes the
git binary and respects its configuration. I'm not sure how much control
you have over the flags that get passed down to the git binary, though).

We could also make it possible to suppress just that advice (with
another advice.* configuration option), but it seems redundant with the
existence of the other two options I discussed above.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Getting rid of "hint: Using 'master' as the name for the initial branch." when not initializing a repository with pygit
  2022-02-01 18:41 Getting rid of "hint: Using 'master' as the name for the initial branch." when initializing a repository with pygit Michal Suchánek
  2022-02-01 19:52 ` Taylor Blau
@ 2022-02-01 19:59 ` Michal Suchánek
  1 sibling, 0 replies; 5+ messages in thread
From: Michal Suchánek @ 2022-02-01 19:59 UTC (permalink / raw)
  To: git

On Tue, Feb 01, 2022 at 07:41:28PM +0100, Michal Suchánek wrote:
> Hello,
> 
> I am running some tests of a project that uses pygit, and the test
> creates a test repository .. using pygit.
> 
> I noticed that in some environments the default branch warning is
> displayed and not others because the git version varies.
> 
> The warning is just noise in the test log so I would like to avoid it,
> and I would like to find a solution that works for git that predates the
> introduction of this warning and the option to silence it as well as
> the future git versions in which the default is subject to change.
> 
> AFAICT there is no clean way to do it. I can set up the global option to
> whatever but I don't want to do that just to run tests.
> 
> I could set the repo local option but before calling
> pygit2.init_repository() there is no repository to configure, and after
> it is too late because I expect the message to be printed by this call.
> 
> Also I cannot rely on pygit to have some latest bells and whistles
> because like git it varies across environments and the whole point of
> running the test in different environments is to verify that it works
> with whatever tool versions are avaialble there.

Actually, I found that the code uses a mix of pygit2 and direct git
calls, and it's the direct call to git init that prints the warning
which can be fixed trivially by using pygit:
@@ -460,7 +460,7 @@ class TestMergeTool(unittest.TestCase):
         self.ks_dir = tempfile.mkdtemp(prefix="gs_ks")
         os.chdir(self.ks_dir)
 
-        subprocess.check_call(("git", "init", "./",), stdout=subprocess.DEVNULL)
+        pygit2.init_repository("./")
         subprocess.check_call(
             ("git", "config", "--add", "mergetool.git-sort.cmd",
              "%s $LOCAL $BASE $REMOTE $MERGED" % (

which begs the question how would I fix it if I was not using pygit. The
git version that does not produce the warning also does not support -b
so it cannot be be universally used with git init. Is there some
reasonable waey to detect this?

Thanks

Michal

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Getting rid of "hint: Using 'master' as the name for the initial branch." when initializing a repository with pygit
  2022-02-01 19:52 ` Taylor Blau
@ 2022-02-01 20:02   ` Michal Suchánek
  2022-02-01 20:15     ` Taylor Blau
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Suchánek @ 2022-02-01 20:02 UTC (permalink / raw)
  To: Taylor Blau; +Cc: git

On Tue, Feb 01, 2022 at 02:52:41PM -0500, Taylor Blau wrote:
> On Tue, Feb 01, 2022 at 07:41:28PM +0100, Michal Suchánek wrote:
> > I noticed that in some environments the default branch warning is
> > displayed and not others because the git version varies.
> >
> > The warning is just noise in the test log so I would like to avoid it,
> > and I would like to find a solution that works for git that predates the
> > introduction of this warning and the option to silence it as well as
> > the future git versions in which the default is subject to change.
> >
> > AFAICT there is no clean way to do it. I can set up the global option to
> > whatever but I don't want to do that just to run tests.
> 
> If you have set the init.defaultBranch configuration, we will suppress
> the hint you're talking about.

That's the problem - there is no way to pass the configuration when
using a library to create a repository.

> 
> Alternatively, you can make sure that `git init` is invoked with the
> `-q` (quiet) flag, which suppresses that warning whether or not you have
> set the init.defaultBranch config.

Yes, that is exactly the option that would do it.

Thanks

Michal

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Getting rid of "hint: Using 'master' as the name for the initial branch." when initializing a repository with pygit
  2022-02-01 20:02   ` Michal Suchánek
@ 2022-02-01 20:15     ` Taylor Blau
  0 siblings, 0 replies; 5+ messages in thread
From: Taylor Blau @ 2022-02-01 20:15 UTC (permalink / raw)
  To: Michal Suchánek; +Cc: Taylor Blau, git

On Tue, Feb 01, 2022 at 09:02:46PM +0100, Michal Suchánek wrote:
> On Tue, Feb 01, 2022 at 02:52:41PM -0500, Taylor Blau wrote:
>
> > If you have set the init.defaultBranch configuration, we will suppress
> > the hint you're talking about.
>
> That's the problem - there is no way to pass the configuration when
> using a library to create a repository.

Of course; but I was suggesting that you set it in $HOME/.gitconfig, or
in your global /etc/gitconfig.

> > Alternatively, you can make sure that `git init` is invoked with the
> > `-q` (quiet) flag, which suppresses that warning whether or not you have
> > set the init.defaultBranch config.
>
> Yes, that is exactly the option that would do it.

OK, I assume that this means that you can pass custom flags down to `git
init` via the library you're using.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-01 20:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 18:41 Getting rid of "hint: Using 'master' as the name for the initial branch." when initializing a repository with pygit Michal Suchánek
2022-02-01 19:52 ` Taylor Blau
2022-02-01 20:02   ` Michal Suchánek
2022-02-01 20:15     ` Taylor Blau
2022-02-01 19:59 ` Getting rid of "hint: Using 'master' as the name for the initial branch." when not " Michal Suchánek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).