|
17 | 17 | require_once(__DIR__.'/../phplib/clilib.php'); |
18 | 18 | require_once(__DIR__.'/amoslib.php'); |
19 | 19 |
|
20 | | -list($options, $unrecognized) = cli_get_params( |
21 | | - array('help' => false, 'commitid' => '', 'filesmodified' => ''), |
22 | | - array('h' => 'help', 'c' => 'commitid', 'f' => 'filesmodified')); |
| 20 | +[$options, $unrecognized] = cli_get_params( |
| 21 | + [ |
| 22 | + 'help' => false, |
| 23 | + 'commitid' => '', |
| 24 | + 'git' => '/usr/bin/git', |
| 25 | + ], |
| 26 | + [ |
| 27 | + 'h' => 'help', |
| 28 | + 'c' => 'commitid', |
| 29 | + 'g' => 'git', |
| 30 | + ] |
| 31 | +); |
23 | 32 |
|
24 | 33 | if ($unrecognized) { |
25 | 34 | $unrecognized = implode("\n ", $unrecognized); |
|
33 | 42 | Options: |
34 | 43 | -h, --help Print out this help |
35 | 44 | -c, --commitid git commit hash |
36 | | --f, --filesmodified files modified by commit (comma seperated) |
| 45 | +-g, --git The path to the git binary |
37 | 46 | "; |
38 | 47 | echo $help; |
39 | 48 | exit(0); |
|
43 | 52 | cli_error('--commitid missing. Use --help to get more info.'); |
44 | 53 | } |
45 | 54 |
|
46 | | -if (empty($options['filesmodified'])) { |
47 | | - cli_error('--filesmodified missing. Use --help to get more info.'); |
| 55 | +$COMMIT = $options['commitid']; |
| 56 | + |
| 57 | +$commitmessagecmd = [ |
| 58 | + escapeshellcmd($options['git']), |
| 59 | + "show", |
| 60 | + "--no-patch", |
| 61 | + "--format=%B", |
| 62 | + escapeshellarg($COMMIT), |
| 63 | +]; |
| 64 | +exec(join(" ", $commitmessagecmd), $output, $returncode); |
| 65 | +if ($returncode !== 0) { |
| 66 | + cli_error("Error running git show command: " . implode("\n", $output)); |
48 | 67 | } |
| 68 | +$message = join("\n", $output); |
49 | 69 |
|
50 | | -$COMMIT = $options['commitid']; |
| 70 | +$filelistcmd = [ |
| 71 | + escapeshellcmd($options['git']), |
| 72 | + "diff-tree", |
| 73 | + "--no-commit-id", |
| 74 | + "--name-only", |
| 75 | + "-r", |
| 76 | + escapeshellarg($COMMIT), |
| 77 | +]; |
| 78 | + |
| 79 | +exec(join(" ", $filelistcmd), $output, $returncode); |
| 80 | +if ($returncode !== 0) { |
| 81 | + cli_error("Error running git diff-tree command: " . implode("\n", $output)); |
| 82 | +} |
| 83 | +$filesmodified = join(",", $output); |
51 | 84 |
|
52 | | -$message = file_get_contents("php://stdin"); |
53 | | -$returncode = amos_script_parser::validate_commit_message($message, $options['filesmodified']); |
| 85 | +$returncode = amos_script_parser::validate_commit_message($message, $filesmodified); |
54 | 86 | exit($returncode); |
0 commit comments