Skip to content

Commit d560b51

Browse files
committed
Attempt to solve rare git merge-base problem
1 parent a6df85e commit d560b51

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Commands/RunCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
155155
$mergeRequest = $buildService->findMergeRequestByBuildRef($projectName, $buildRef);
156156

157157
$repo = new GitRepository(getcwd());
158-
$repo->fetch();
159-
$lastCommonCommit = $repo->getMergeBase($mergeRequest['target_branch'], $buildRef);
158+
$targetCommit = $repo->getLatestCommitForBranch($mergeRequest['target_branch']);
159+
$lastCommonCommit = $repo->getMergeBase($targetCommit, $buildRef);
160160

161161

162162
list($previousCodeCoverageProvider, $previousMethodsProvider) = $this->getMeasuresFromCommit($buildService, $mergeRequest['target_project_id'], $lastCommonCommit, $cloverFilePath, $crap4JFilePath);

src/Git/GitRepository.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ public function getMergeBase(string $commit1, string $commit2) : string
1212

1313
return $results[0];
1414
}
15+
16+
public function getLatestCommitForBranch(string $branch) : string
17+
{
18+
$results = $this->extractFromCommand('git log -n 1 --pretty=format:"%H" ' . escapeshellarg($branch));
19+
20+
return $results[0];
21+
}
1522
}

0 commit comments

Comments
 (0)