@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.

When observing a repository in Git, just "fetch <url>" without worrying about the "origin" remote

Summary:
Depends on D20420. Ref T13277. We currently spend substantial effort trying to detect and correct the URL of the "origin" remote in Git repositories.

I believe this is unnecessary, and we can always `git fetch <url> ...` to get the desired result instead of `git muck-with-origin + git fetch origin ...`. We already do this in the more recent parts of the codebase (e.g., intracluster sync) and it works correctly in every case I'm aware of.

Test Plan:

- Grepped for `origin`, ` origin `.
- Ran `bin/repository update ...` to fetch a mirrored repository.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13277

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

+4 -136
-4
src/applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php
··· 128 128 private function discoverGitCommits() { 129 129 $repository = $this->getRepository(); 130 130 131 - if (!$repository->isHosted()) { 132 - $this->verifyGitOrigin($repository); 133 - } 134 - 135 131 $heads = id(new DiffusionLowLevelGitRefQuery()) 136 132 ->setRepository($repository) 137 133 ->execute();
-117
src/applications/repository/engine/PhabricatorRepositoryEngine.php
··· 70 70 return PhabricatorGlobalLock::newLock($lock_key, $lock_parts); 71 71 } 72 72 73 - 74 - /** 75 - * Verify that the "origin" remote exists, and points at the correct URI. 76 - * 77 - * This catches or corrects some types of misconfiguration, and also repairs 78 - * an issue where Git 1.7.1 does not create an "origin" for `--bare` clones. 79 - * See T4041. 80 - * 81 - * @param PhabricatorRepository Repository to verify. 82 - * @return void 83 - */ 84 - protected function verifyGitOrigin(PhabricatorRepository $repository) { 85 - try { 86 - list($remotes) = $repository->execxLocalCommand( 87 - 'remote show -n origin'); 88 - } catch (CommandException $ex) { 89 - throw new PhutilProxyException( 90 - pht( 91 - 'Expected to find a Git working copy at path "%s", but the '. 92 - 'path exists and is not a valid working copy. If you remove '. 93 - 'this directory, the daemons will automatically recreate it '. 94 - 'correctly. Phabricator will not destroy the directory for you '. 95 - 'because it can not be sure that it does not contain important '. 96 - 'data.', 97 - $repository->getLocalPath()), 98 - $ex); 99 - } 100 - 101 - $matches = null; 102 - if (!preg_match('/^\s*Fetch URL:\s*(.*?)\s*$/m', $remotes, $matches)) { 103 - throw new Exception( 104 - pht( 105 - "Expected '%s' in '%s'.", 106 - 'Fetch URL', 107 - 'git remote show -n origin')); 108 - } 109 - 110 - $remote_uri = $matches[1]; 111 - $expect_remote = $repository->getRemoteURI(); 112 - 113 - if ($remote_uri == 'origin') { 114 - // If a remote does not exist, git pretends it does and prints out a 115 - // made up remote where the URI is the same as the remote name. This is 116 - // definitely not correct. 117 - 118 - // Possibly, we should use `git remote --verbose` instead, which does not 119 - // suffer from this problem (but is a little more complicated to parse). 120 - $valid = false; 121 - $exists = false; 122 - } else { 123 - $normal_type_git = PhabricatorRepositoryURINormalizer::TYPE_GIT; 124 - 125 - $remote_normal = id(new PhabricatorRepositoryURINormalizer( 126 - $normal_type_git, 127 - $remote_uri))->getNormalizedPath(); 128 - 129 - $expect_normal = id(new PhabricatorRepositoryURINormalizer( 130 - $normal_type_git, 131 - $expect_remote))->getNormalizedPath(); 132 - 133 - $valid = ($remote_normal == $expect_normal); 134 - $exists = true; 135 - } 136 - 137 - // These URIs may have plaintext HTTP credentials. If they do, censor 138 - // them for display. See T12945. 139 - $display_remote = phutil_censor_credentials($remote_uri); 140 - $display_expect = phutil_censor_credentials($expect_remote); 141 - 142 - if (!$valid) { 143 - if (!$exists) { 144 - // If there's no "origin" remote, just create it regardless of how 145 - // strongly we own the working copy. There is almost no conceivable 146 - // scenario in which this could do damage. 147 - $this->log( 148 - pht( 149 - 'Remote "origin" does not exist. Creating "origin", with '. 150 - 'URI "%s".', 151 - $expect_remote)); 152 - $repository->execxLocalCommand( 153 - 'remote add origin %P', 154 - $repository->getRemoteURIEnvelope()); 155 - 156 - // NOTE: This doesn't fetch the origin (it just creates it), so we won't 157 - // know about origin branches until the next "pull" happens. That's fine 158 - // for our purposes, but might impact things in the future. 159 - } else { 160 - if ($repository->canDestroyWorkingCopy()) { 161 - // Bad remote, but we can try to repair it. 162 - $this->log( 163 - pht( 164 - 'Remote "origin" exists, but is pointed at the wrong URI, "%s". '. 165 - 'Resetting origin URI to "%s.', 166 - $remote_uri, 167 - $expect_remote)); 168 - $repository->execxLocalCommand( 169 - 'remote set-url origin %P', 170 - $repository->getRemoteURIEnvelope()); 171 - } else { 172 - // Bad remote and we aren't comfortable repairing it. 173 - $message = pht( 174 - 'Working copy at "%s" has a mismatched origin URI, "%s". '. 175 - 'The expected origin URI is "%s". Fix your configuration, or '. 176 - 'set the remote URI correctly. To avoid breaking anything, '. 177 - 'Phabricator will not automatically fix this.', 178 - $repository->getLocalPath(), 179 - $display_remote, 180 - $display_expect); 181 - throw new Exception($message); 182 - } 183 - } 184 - } 185 - } 186 - 187 - 188 - 189 - 190 73 /** 191 74 * @task internal 192 75 */
+4 -15
src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
··· 122 122 $repository->getDisplayName())); 123 123 124 124 if ($is_git) { 125 - $this->verifyGitOrigin($repository); 126 125 $this->executeGitUpdate(); 127 126 } else if ($is_hg) { 128 127 $this->executeMercurialUpdate(); ··· 352 351 353 352 $this->logRefDifferences($remote_refs, $local_refs); 354 353 355 - // Force the "origin" URI to the configured value. 356 - $repository->execxLocalCommand( 357 - 'remote set-url origin -- %P', 358 - $repository->getRemoteURIEnvelope()); 359 - 360 - if ($repository->isWorkingCopyBare()) { 361 - // For bare working copies, we need this magic incantation. 362 - $future = $repository->getRemoteCommandFuture( 363 - 'fetch origin %s --prune', 364 - '+refs/*:refs/*'); 365 - } else { 366 - $future = $repository->getRemoteCommandFuture( 367 - 'fetch --all --prune'); 368 - } 354 + $future = $repository->getRemoteCommandFuture( 355 + 'fetch %P %s --prune', 356 + $repository->getRemoteURIEnvelope(), 357 + '+refs/*:refs/*'); 369 358 370 359 $future 371 360 ->setCWD($path)