@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplify non-bare working copy rules for the new "git fetch" strategy

Summary:
Ref T13280. In D20421, I changed our observe strategy to `git fetch <uri>` in all cases.

This doesn't work in an ancient, non-bare repository if `master` is checked out and `master` is also fetch: `git` refuses to overwrite the local ref unless we pass `--update-head-ok`. Pass this flag.

Also, remove some code which examines branches and tags in a special way for non-bare working copies. The old `git fetch <origin>` code without explicit revsets meant that `refs/remotes/orgin/heads/xyz` got updated instead of `refs/heads/xyz`. We now update our local refs in all cases (bare and non-bare) so we can throw away this special casing.

Test Plan:
- Replaced a modern bare working copy with a non-bare working copy by explicitly using `git clone` without `--bare`.
- Ran `bin/repository update`, hit the `--update-head-ok` error. Applied the patch, got a clean update.
- Used the "repository.branchquery" API method...
- ...with "contains" to trigger the "git branch" case. Got identical results after removing the special casing.
- ...without "contains" to trigger the "low level ref" case. Got identical results after removing the special casing.
- Grepped for `isWorkingCopyBare()`. The only remaining callsites deal with hook paths, and genuinely need to be specialized.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13280

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

+12 -25
+6 -16
src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php
··· 46 46 47 47 // NOTE: We can't use DiffusionLowLevelGitRefQuery here because 48 48 // `git for-each-ref` does not support `--contains`. 49 - if ($repository->isWorkingCopyBare()) { 50 - list($stdout) = $repository->execxLocalCommand( 51 - 'branch --verbose --no-abbrev --contains %s -- %Ls', 52 - $contains, 53 - $patterns_argv); 54 - $ref_map = DiffusionGitBranch::parseLocalBranchOutput( 55 - $stdout); 56 - } else { 57 - list($stdout) = $repository->execxLocalCommand( 58 - 'branch -r --verbose --no-abbrev --contains %s -- %Ls', 59 - $contains, 60 - $patterns_argv); 61 - $ref_map = DiffusionGitBranch::parseRemoteBranchOutput( 62 - $stdout, 63 - DiffusionGitBranch::DEFAULT_GIT_REMOTE); 64 - } 49 + list($stdout) = $repository->execxLocalCommand( 50 + 'branch --verbose --no-abbrev --contains %s -- %Ls', 51 + $contains, 52 + $patterns_argv); 53 + $ref_map = DiffusionGitBranch::parseLocalBranchOutput( 54 + $stdout); 65 55 66 56 $refs = array(); 67 57 foreach ($ref_map as $ref => $commit) {
+1 -8
src/applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php
··· 33 33 34 34 $prefixes = array(); 35 35 36 - if ($repository->isWorkingCopyBare()) { 37 - $branch_prefix = 'refs/heads/'; 38 - } else { 39 - $remote = DiffusionGitBranch::DEFAULT_GIT_REMOTE; 40 - $branch_prefix = 'refs/remotes/'.$remote.'/'; 41 - } 42 - 36 + $branch_prefix = 'refs/heads/'; 43 37 $tag_prefix = 'refs/tags/'; 44 - 45 38 46 39 if ($with_refs || count($ref_types) > 1) { 47 40 // If we're loading refs or more than one type of ref, just query
+5 -1
src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
··· 366 366 367 367 $fetch_rules = $this->getGitFetchRules($repository); 368 368 369 + // For very old non-bare working copies, we need to use "--update-head-ok" 370 + // to tell Git that it is allowed to overwrite whatever is currently 371 + // checked out. See T13280. 372 + 369 373 $future = $repository->getRemoteCommandFuture( 370 - 'fetch --prune -- %P %Ls', 374 + 'fetch --prune --update-head-ok -- %P %Ls', 371 375 $repository->getRemoteURIEnvelope(), 372 376 $fetch_rules); 373 377