Skip to content

Support more than just "master" as the default branch #648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Command/RecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private function displayPackageInformation(Recipe $recipe)
$lockRef = $recipeLock['recipe']['ref'] ?? null;
$lockRepo = $recipeLock['recipe']['repo'] ?? null;
$lockFiles = $recipeLock['files'] ?? null;
$lockBranch = $recipeLock['recipe']['branch'] ?? null;

$status = '<comment>up to date</comment>';
if ($recipe->isAuto()) {
Expand All @@ -147,15 +148,14 @@ private function displayPackageInformation(Recipe $recipe)
$status = '<comment>update available</comment>';
}

$branch = $recipeLock['recipe']['branch'] ?? 'master';
$gitSha = null;
$commitDate = null;
if (null !== $lockRef && null !== $lockRepo) {
try {
list($gitSha, $commitDate) = $this->findRecipeCommitDataFromTreeRef(
$recipe->getName(),
$lockRepo,
$branch,
$lockBranch ?? '',
$recipeLock['version'],
$lockRef
);
Expand All @@ -172,7 +172,7 @@ private function displayPackageInformation(Recipe $recipe)
'https://%s/tree/%s/%s/%s',
$lockRepo,
// if something fails, default to the branch as the closest "sha"
$gitSha ?? $branch,
$gitSha ?? $lockBranch,
$recipe->getName(),
$recipeLock['version']
);
Expand All @@ -186,7 +186,7 @@ private function displayPackageInformation(Recipe $recipe)
$historyUrl = sprintf(
'https://%s/commits/%s/%s',
$lockRepo,
$branch,
$lockBranch,
$recipe->getName()
);

Expand Down
9 changes: 9 additions & 0 deletions src/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ public function getRecipes(array $operations): array
$branchAliases = $package->getExtra()['branch-alias'];
if (
(isset($branchAliases[$version]) && $alias = $branchAliases[$version]) ||
(isset($branchAliases['dev-main']) && $alias = $branchAliases['dev-main']) ||
(isset($branchAliases['dev-trunk']) && $alias = $branchAliases['dev-trunk']) ||
(isset($branchAliases['dev-develop']) && $alias = $branchAliases['dev-develop']) ||
(isset($branchAliases['dev-default']) && $alias = $branchAliases['dev-default']) ||
(isset($branchAliases['dev-latest']) && $alias = $branchAliases['dev-latest']) ||
(isset($branchAliases['dev-next']) && $alias = $branchAliases['dev-next']) ||
(isset($branchAliases['dev-current']) && $alias = $branchAliases['dev-current']) ||
(isset($branchAliases['dev-support']) && $alias = $branchAliases['dev-support']) ||
(isset($branchAliases['dev-tip']) && $alias = $branchAliases['dev-tip']) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we even have all these cases ? To match the behavior of composer, only $branchAliases[$version] should be relevant. Branch aliases defined for other branches are totally ignored by composer (though they are allowed, so that you don't have to remove them between branches which would be a mess)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks at the branch-alias to decide which version of the recipe should be installed.
We can support more items than composer here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking the branch alias of dev-tip when the installed version is not dev-tip looks weird to me. You want to install the recipe for the installed version, not for a random version.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still pretty common when checking out a custom dev-branch without aliasing it. E.g. for Symfony components, falling back to the dev-master alias is the best way to guess the version of the branch. That's why there is logic IIUC.

(isset($branchAliases['dev-master']) && $alias = $branchAliases['dev-master'])
) {
$version = $alias;
Expand Down
2 changes: 1 addition & 1 deletion src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ private function getFlexId()

private function formatOrigin(string $origin): string
{
// symfony/translation:[email protected]/symfony/recipes:master
// symfony/translation:[email protected]/symfony/recipes:branch
if (!preg_match('/^([^:]++):([^@]++)@(.+)$/', $origin, $matches)) {
return $origin;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Recipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getURL(): string
return '';
}

// symfony/translation:[email protected]/symfony/recipes:master
// symfony/translation:[email protected]/symfony/recipes:branch
if (!preg_match('/^([^:]++):([^@]++)@([^:]++):(.+)$/', $this->data['origin'], $matches)) {
// that excludes auto-generated recipes, which is what we want
return '';
Expand Down