public final function executeQuery() { $request = $this->getRequest(); $repository = $request->getRepository(); list($contains) = $repository->execxLocalCommand('branch -r --verbose --no-abbrev --contains %s', $request->getCommit()); return DiffusionGitBranchQuery::parseGitRemoteBranchOutput($contains, DiffusionBranchInformation::DEFAULT_GIT_REMOTE); }
public function testRemoteBranchParser() { $output = <<<EOTXT origin/HEAD -> origin/master origin/accent-folding bfaea2e72197506e028c604cd1a294b6e37aa17d Add... origin/eventordering 185a90a3c1b0556015e5f318fb86ccf8f7a6f3e3 RFC: Order... origin/master 713f1fc54f9cfc830acbf6bbdb46a2883f772896 Automat... alternate/stuff 4444444444444444444444444444444444444444 Hmm... EOTXT; $this->assertEqual(array('origin/accent-folding' => 'bfaea2e72197506e028c604cd1a294b6e37aa17d', 'origin/eventordering' => '185a90a3c1b0556015e5f318fb86ccf8f7a6f3e3', 'origin/master' => '713f1fc54f9cfc830acbf6bbdb46a2883f772896', 'alternate/stuff' => '4444444444444444444444444444444444444444'), DiffusionGitBranchQuery::parseGitRemoteBranchOutput($output)); $this->assertEqual(array('accent-folding' => 'bfaea2e72197506e028c604cd1a294b6e37aa17d', 'eventordering' => '185a90a3c1b0556015e5f318fb86ccf8f7a6f3e3', 'master' => '713f1fc54f9cfc830acbf6bbdb46a2883f772896'), DiffusionGitBranchQuery::parseGitRemoteBranchOutput($output, 'origin')); }
public function testRemoteBranchParser() { $output = <<<EOTXT origin/HEAD -> origin/master origin/accent-folding bfaea2e72197506e028c604cd1a294b6e37aa17d Add... origin/eventordering 185a90a3c1b0556015e5f318fb86ccf8f7a6f3e3 RFC: Order... origin/master 713f1fc54f9cfc830acbf6bbdb46a2883f772896 Automat... alternate/stuff 4444444444444444444444444444444444444444 Hmm... origin/HEAD 713f1fc54f9cfc830acbf6bbdb46a2883f772896 origin/weekend-refactoring 6e947ab0498b82075ca6195ac168385a11326c4b alternate/release-1.0.0 9ddd5d67962dd89fa167f9989954468b6c517b87 EOTXT; $this->assertEqual(array('origin/accent-folding' => 'bfaea2e72197506e028c604cd1a294b6e37aa17d', 'origin/eventordering' => '185a90a3c1b0556015e5f318fb86ccf8f7a6f3e3', 'origin/master' => '713f1fc54f9cfc830acbf6bbdb46a2883f772896', 'alternate/stuff' => '4444444444444444444444444444444444444444', 'origin/weekend-refactoring' => '6e947ab0498b82075ca6195ac168385a11326c4b', 'alternate/release-1.0.0' => '9ddd5d67962dd89fa167f9989954468b6c517b87'), DiffusionGitBranchQuery::parseGitRemoteBranchOutput($output)); $this->assertEqual(array('accent-folding' => 'bfaea2e72197506e028c604cd1a294b6e37aa17d', 'eventordering' => '185a90a3c1b0556015e5f318fb86ccf8f7a6f3e3', 'master' => '713f1fc54f9cfc830acbf6bbdb46a2883f772896', 'weekend-refactoring' => '6e947ab0498b82075ca6195ac168385a11326c4b'), DiffusionGitBranchQuery::parseGitRemoteBranchOutput($output, 'origin')); }
protected function discoverCommits() { // NOTE: PhabricatorRepositoryGitFetchDaemon does the actual pulls, this // just parses HEAD. $repository = $this->getRepository(); $vcs = $repository->getVersionControlSystem(); if ($vcs != PhabricatorRepositoryType::REPOSITORY_TYPE_GIT) { throw new Exception("Repository is not a git repository."); } list($remotes) = $repository->execxLocalCommand('remote show -n origin'); $matches = null; if (!preg_match('/^\\s*Fetch URL:\\s*(.*?)\\s*$/m', $remotes, $matches)) { throw new Exception("Expected 'Fetch URL' in 'git remote show -n origin'."); } self::verifySameGitOrigin($matches[1], $repository->getRemoteURI(), $repository->getLocalPath()); list($stdout) = $repository->execxLocalCommand('branch -r --verbose --no-abbrev'); $branches = DiffusionGitBranchQuery::parseGitRemoteBranchOutput($stdout, $only_this_remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE); $got_something = false; $tracked_something = false; foreach ($branches as $name => $commit) { if (!$repository->shouldTrackBranch($name)) { continue; } $tracked_something = true; if ($this->isKnownCommit($commit)) { continue; } else { $this->discoverCommit($commit); $got_something = true; } } if (!$tracked_something) { $repo_name = $repository->getName(); $repo_callsign = $repository->getCallsign(); throw new Exception("Repository r{$repo_callsign} '{$repo_name}' has no tracked branches! " . "Verify that your branch filtering settings are correct."); } return $got_something; }
protected function discoverCommits() { // NOTE: PhabricatorRepositoryGitFetchDaemon does the actual pulls, this // just parses HEAD. $repository = $this->getRepository(); $vcs = $repository->getVersionControlSystem(); if ($vcs != PhabricatorRepositoryType::REPOSITORY_TYPE_GIT) { throw new Exception("Repository is not a git repository."); } $repository_phid = $repository->getPHID(); $repo_base = $repository->getDetail('local-path'); list($stdout) = execx('(cd %s && git branch -r --verbose --no-abbrev)', $repo_base); $branches = DiffusionGitBranchQuery::parseGitRemoteBranchOutput($stdout); $got_something = false; foreach ($branches as $name => $commit) { if ($this->isKnownCommit($commit)) { continue; } else { $this->discoverCommit($commit); $got_something = true; } } return $got_something; }
/** * @task git */ private function executeGitDiscover(PhabricatorRepository $repository) { list($remotes) = $repository->execxLocalCommand('remote show -n origin'); $matches = null; if (!preg_match('/^\\s*Fetch URL:\\s*(.*?)\\s*$/m', $remotes, $matches)) { throw new Exception("Expected 'Fetch URL' in 'git remote show -n origin'."); } self::executeGitVerifySameOrigin($matches[1], $repository->getRemoteURI(), $repository->getLocalPath()); list($stdout) = $repository->execxLocalCommand('branch -r --verbose --no-abbrev'); $branches = DiffusionGitBranchQuery::parseGitRemoteBranchOutput($stdout, $only_this_remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE); $callsign = $repository->getCallsign(); $tracked_something = false; $this->log("Discovering commits in repository '{$callsign}'..."); foreach ($branches as $name => $commit) { $this->log("Examining branch '{$name}', at {$commit}."); if (!$repository->shouldTrackBranch($name)) { $this->log("Skipping, branch is untracked."); continue; } $tracked_something = true; if ($this->isKnownCommit($repository, $commit)) { $this->log("Skipping, HEAD is known."); continue; } $this->log("Looking for new commits."); $this->executeGitDiscoverCommit($repository, $commit, $name, false); } if (!$tracked_something) { $repo_name = $repository->getName(); $repo_callsign = $repository->getCallsign(); throw new Exception("Repository r{$repo_callsign} '{$repo_name}' has no tracked branches! " . "Verify that your branch filtering settings are correct."); } $this->log("Discovering commits on autoclose branches..."); foreach ($branches as $name => $commit) { $this->log("Examining branch '{$name}', at {$commit}'."); if (!$repository->shouldTrackBranch($name)) { $this->log("Skipping, branch is untracked."); continue; } if (!$repository->shouldAutocloseBranch($name)) { $this->log("Skipping, branch is not autoclose."); continue; } if ($this->isKnownCommitOnAnyAutocloseBranch($repository, $commit)) { $this->log("Skipping, commit is known on an autoclose branch."); continue; } $this->log("Looking for new autoclose commits."); $this->executeGitDiscoverCommit($repository, $commit, $name, true); } }