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)
Fri, Apr 19, 3:09 AM
Unknown Object (File)
Thu, Apr 11, 7:13 AM
Unknown Object (File)
Sat, Mar 30, 8:01 AM
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)
Mar 18 2024, 8:12 PM
Unknown Object (File)
Mar 10 2024, 3:02 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
Branch
autoclose16
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 22609
Build 30981: Run Core Tests
Build 30980: arc lint + arc unit

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
464

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
464

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