1
0
Fork 0

Fix a few edge cases in unpushed change handling

pull/9532/head
Jordi Boggiano 2020-11-26 16:03:38 +01:00
parent f86b3ad0fe
commit 1fb6b03e03
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 9 additions and 2 deletions

View File

@ -239,6 +239,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
// use the first match as branch name for now
$branch = $candidateBranches[0];
$unpushedChanges = null;
$branchNotFoundError = false;
// do two passes, as if we find anything we want to fetch and then re-try
for ($i = 0; $i <= 1; $i++) {
@ -259,8 +260,14 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
// this is bad as we have no reference point to do a diff so we just bail listing
// the branch as being unpushed
if (!$remoteBranches) {
$unpushedChanges = 'Branch ' . $branch . ' could not be found on the origin remote and appears to be unpushed';
$unpushedChanges = 'Branch ' . $branch . ' could not be found on any remote and appears to be unpushed';
$branchNotFoundError = true;
} else {
// if first iteration found no remote branch but it has now found some, reset $unpushedChanges
// so we get the real diff output no matter its length
if ($branchNotFoundError) {
$unpushedChanges = null;
}
foreach ($remoteBranches as $remoteBranch) {
$command = sprintf('git diff --name-status %s...%s --', $remoteBranch, $branch);
if (0 !== $this->process->execute($command, $output, $path)) {
@ -270,7 +277,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
$output = trim($output);
// keep the shortest diff from all remote branches we compare against
if ($unpushedChanges === null || strlen($output) < strlen($unpushedChanges)) {
$unpushedChanges = $output ?: null;
$unpushedChanges = $output;
}
}
}