Skip to content

Commit

Permalink
Pretendable script
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 21, 2024
1 parent e654f4d commit c59fae7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/bin/pick.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Internal helper to speed up branching up cherry picked commits for pull requests

// Check if we have the correct number of arguments
if ($argc !== 3) {
if ($argc !== 3 && $argc !== 4) {
echo "\033[31mError: Invalid number of arguments\033[0m\n";
echo "\033[33mUsage:\033[0m php bin/pick.php <commit-hash> <new-branch-name>\n";
echo "\033[33mExample:\033[0m php bin/pick.php abc123 feature-branch\n";
Expand All @@ -14,6 +14,7 @@
// Get arguments
$hash = $argv[1];
$branch = $argv[2];
$pretend = $argv[3] === '--pretend';

// Get the commit message
exec("git show $hash --pretty=format:\"%s%n%b\" -s", $output, $returnCode);
Expand All @@ -33,15 +34,15 @@
}

// Create new branch from master
exec("git checkout -b $branch master", $output, $returnCode);
exec(($pretend ? 'echo ' : '') . "git checkout -b $branch master", $output, $returnCode);

if ($returnCode !== 0) {
echo "\033[31mError creating new branch: $branch\033[0m\n";
exit(1);
}

// Cherry-pick the commit
exec("git cherry-pick $hash", $output, $returnCode);
exec(($pretend ? 'echo ' : '') . "git cherry-pick $hash", $output, $returnCode);

if ($returnCode !== 0) {
echo "\033[31mError cherry-picking commit: $hash\033[0m\n";
Expand Down

0 comments on commit c59fae7

Please sign in to comment.