HomePhabricator

In Git repositories, use "git symbolic-ref HEAD ..." to select the default…

Description

In Git repositories, use "git symbolic-ref HEAD ..." to select the default branch

Summary:
Depends on D20434. Fixes T5963. Broadly, the issue here is that when:

  • You create a new, empty repository.
  • Then, you work on some branch other than master, without ever creating master.

...you get a warning on git clone:

warning: remote HEAD refers to nonexistent ref, unable to checkout

To fix this, point the symbolic-ref HEAD at refs/heads/<default-branch> after installing commit hooks.

This fixes the warning, and also means that git clone will check out the repository default branch by default, which is nice.

There are a few caveats about this behavior (see T5963 for discussion) but nothing too substantial.

The only real issue is that Git prevents deletion of the default branch without a config setting. Just set that settting.

Test Plan:
See T5963.

In a repository, set HEAD to point somewhere invalid. Ran bin/repository update .... Saw HEAD pointed back at the repository default branch.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T5963

Differential Revision: https://secure.phabricator.com/D20435