Created
June 8, 2024 13:58
-
-
Save brandonkelly/6a88599b254b755decb6d29f3d777651 to your computer and use it in GitHub Desktop.
Revisions
-
brandonkelly created this gist
Jun 8, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #!/usr/bin/env php <?php // ----------------------------------------------------------------------------- // Usage: `cherrypath.php <upstream> <head> <path>` // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Runs `git cherry -v <upstream> <head>` and filters the output // to only include SHAs where <path> was modified. // ----------------------------------------------------------------------------- if (!isset($argv[1], $argv[2], $argv[3]) || isset($argv[4])) { echo "Usage: cherrypath.php <upstream> <head> <path>\n"; exit(1); } exec(sprintf('git cherry -v %s %s', $argv[1], $argv[2]), $cherryOutput, $cherryCode); if ($cherryCode !== 0) { echo sprintf("git-cherry failed: %s\n", implode("\n", $cherryOutput)); exit(1); } exec(sprintf('git log --format=oneline -- %s', $argv[3]), $logOutput, $logCode); if ($logCode !== 0) { echo sprintf("git-log failed: %s\n", implode("\n", $logOutput)); exit(1); } // index the shas that involved the <path> $logShas = []; foreach ($logOutput as $line) { $sha = substr($line, 0, 40); $logShas[$sha] = true; } // output the git-cherry lines for the filtered shas foreach ($cherryOutput as $line) { $sha = substr($line, 2, 40); if (isset($logShas[$sha])) { echo "$line\n"; } }