GetComponents assumes that default branch name is "master"

Issue #2580 new
Roland Haas created an issue

When using a stanza like this:

!TARGET   = $ARR
!TYPE     = git
!URL      = git@github.com:rhaas/Foo.git
!REPO_BRANCH = main
!REPO_PATH= $2
!CHECKOUT =
Foo/Foo

GetComponents fails with:

> bin/GetComponents --verbose --root . thornlists/grhydrox.th
-----------------------------------------------------------------
  Checking out module: Foo/Foo
      from repository: git@github.com:rhaas/Foo.git
                 into: ./arrangements
Executing: mkdir -p './repos'
Executing: git clone git@github.com:rhaas/Foo.git './repos/Foo'
Cloning into './repos/Foo'...
Executing: git tag -l
       In: './repos/Foo'
Executing: git checkout --track -b main origin/main
       In: './repos/Foo'
fatal: A branch named 'main' already exists.
Executing: mv './repos/Foo' './repos/Foo.branch.failed.1'

Warning: Could not checkout Foo/Foo, unable to switch to branch main. Any existing symlinks to Foo/Foo will be broken

This can be made to work by leaving out the REPO_BRANCH option altogether, which is doable but not ideal.

Comments (2)

  1. Roland Haas reporter

    Hackathon (Perl).

    A way to get the default branch name is using this code:

    default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
    

  2. Roland Haas reporter

    hmm, this would seem to likely cause failures also when we have the release branches set and this be (much) more severe than “minor”. Needs testing.

  3. Log in to comment