From: Stefan Sperling Subject: Re: got regress: set inital branch to 'master' To: Thomas Adam Cc: gameoftrees@openbsd.org Date: Wed, 29 Sep 2021 21:03:56 +0200 On Wed, Sep 29, 2021 at 07:22:13PM +0100, Thomas Adam wrote: > Hi, > > In newer versions of git (2.28.0, released in July 2020), the tooling gained > support for initialising a default branch name other than 'master'. By default, > this branch name is now called 'main'. > > However, there will be quite a few installations out there where the version > of git has not been updated to this version. The cmdline/ regress tests > assume 'master' as the default branch name still for expected test output. > > Until such time that there is more confidence that we can change this to > 'main' in the expected test output, it's possible to tell git to create a > specific default branch name at init time, with: > > git -c init.defaultbranch=master init . > > Older versions of git which do not understnad this option will still default > to 'master', and will seemingly ignore the option, hence: > > git -c inittypo.defaultbranch=master init . > > Works, and gives me a branch called 'main', which I would expect. We should not have to rely on Git's UI for this. What matters to us are fundamental assumptions Git makes about its own repository format. We can rely on those assumptions, hoping they won't change in a way that would break Got as it has been implemented. When Git creates a new repository there are no branch references yet. There's only the symbolic HEAD reference which contains the default branch name. This name can be changed with a simple sed command that will work everywhere. So I would suggest the following: diff fa161f0bf4d34a678ba30bf62f5e8eec44ceb931 /home/stsp/src/got blob - 260f6406dd2eba1355d668e2c054b7f09f9f1ee5 file + regress/cmdline/common.sh --- regress/cmdline/common.sh +++ regress/cmdline/common.sh @@ -29,6 +29,17 @@ export MALLOC_OPTIONS=S git_init() { git init -q "$1" + + # Switch the default branch to match our test expectations if needed. + # Only need to change HEAD since 'git init' did not create any refs. + # Relying on implementation details of 'git init' is no problem for us. + # We want to be alerted when Git changes fundamental assumptions such + # as what an empty repository looks like and where the default branch + # is set. In such cases Got's own tooling might well need to change + # its behaviour, too, and our tests should fail. + # TODO: Update all tests to assume 'main' instead of 'master' and + # switch this search/replace expression around. + sed -i -e 's#refs/heads/main#refs/heads/master#' "$1/.git/HEAD" } maybe_pack_repo()