Skip to content

Instantly share code, notes, and snippets.

@Flyingmana
Created June 28, 2020 10:25
Show Gist options
  • Save Flyingmana/201fc85ae43d4666f636431bb59755aa to your computer and use it in GitHub Desktop.
Save Flyingmana/201fc85ae43d4666f636431bb59755aa to your computer and use it in GitHub Desktop.
scripts to help change the default branch in PHP projects
<?php
passthru("cd ".__DIR__);
if (!isset($argv[1])) {
throw new Exception("no argument?");
}
$repo = $argv[1];
$directory = "4_".basename($repo, '.git');
var_dump($repo, $directory);
passthru("git clone $repo $directory");
echo "clone finished";
chdir($directory);
require(__DIR__ . '/update_repository_branch.php');
<?php
$newDefaultBranch = "develop";
$currentDirectory = getcwd();
$composerJsonPath = $currentDirectory."/composer.json";
echo $composerJsonPath;
$composerLockPath = $currentDirectory."/composer.lock";
$composerJson = json_decode(file_get_contents($composerJsonPath),true);
if (!isset($composerJson['extra'])) {
$composerJson['extra'] = [];
}
if (!isset($composerJson['extra']['branch-alias'])) {
$composerJson['extra']['branch-alias'] = [];
}
$composerJson['extra']['branch-alias']['dev-master'] = $newDefaultBranch;
file_put_contents($composerJsonPath, json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ));
if(file_exists($composerLockPath)) {
$command = 'composer update --lock --ignore-platform-reqs';
echo $command;
passthru($command);
passthru('git add composer.lock');
}
passthru('git add composer.json');
passthru('git commit -m "update branch Alias"');
passthru('git checkout -b '.$newDefaultBranch);
//passthru('git push origin master');
//passthru('git push origin '.$newDefaultBranch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment