Page MenuHomePhabricator

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

Authored by epriestley on Apr 16 2019, 1:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Mar 27, 1:58 AM
Unknown Object (File)
Wed, Mar 27, 1:58 AM
Unknown Object (File)
Wed, Mar 27, 1:58 AM
Unknown Object (File)
Mon, Mar 18, 8:12 PM
Unknown Object (File)
Sun, Mar 10, 3:02 AM
Unknown Object (File)
Fri, Mar 1, 5:11 AM
Unknown Object (File)
Feb 21 2024, 1:25 PM
Unknown Object (File)
Feb 4 2024, 2:06 AM
Subscribers
None

Details

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.

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

  • Do this for both hosted and observed repositories. It's not super common to clone from Phabricator's copy of an observed repository, but it does happen sometimes and we might as well be consistent.
  • Ran bin/repository update ... for both hosted and observed repositories, saw config/symbolic-ref in both cases.
epriestley retitled this revision from In hosted Git repositories, use "git symbolic-ref HEAD ..." to select the default branch to In Git repositories, use "git symbolic-ref HEAD ..." to select the default branch.Apr 16 2019, 2:35 PM
amckinley added inline comments.
src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
439

denyDeleteCurrent

This revision is now accepted and ready to land.Apr 17 2019, 9:17 PM
This revision was automatically updated to reflect the committed changes.
src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
439

Oops, missed this. I'll get it in a followup.