Skip to content

Commit 82df354

Browse files
committed
Allow AMOS to perform git commands
This prevent issues when passing a large number of changes files to the amos script. Previously the git commands were run in the shell script and values passed to the php script, but where there are large numbers of files this breaks because PHP hits ARG limits.
1 parent 6cdb6d2 commit 82df354

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

verify_commit_messages/check_amos.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717
require_once(__DIR__.'/../phplib/clilib.php');
1818
require_once(__DIR__.'/amoslib.php');
1919

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+
);
2332

2433
if ($unrecognized) {
2534
$unrecognized = implode("\n ", $unrecognized);
@@ -33,7 +42,7 @@
3342
Options:
3443
-h, --help Print out this help
3544
-c, --commitid git commit hash
36-
-f, --filesmodified files modified by commit (comma seperated)
45+
-g, --git The path to the git binary
3746
";
3847
echo $help;
3948
exit(0);
@@ -43,12 +52,35 @@
4352
cli_error('--commitid missing. Use --help to get more info.');
4453
}
4554

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));
4867
}
68+
$message = join("\n", $output);
4969

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);
5184

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);
5486
exit($returncode);

verify_commit_messages/verify_commit_messages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ for c in ${commits}; do
129129
else
130130
# Run AMOS checks.
131131
modifiedfiles=$(git diff-tree --no-commit-id --name-only -r ${c} | tr '\n' ',')
132-
echo "$message" | $phpcmd $mydir/check_amos.php --commitid=${c} --filesmodified=$modifiedfiles
132+
$phpcmd $mydir/check_amos.php --git="${gitcmd}" --commitid=${c}
133133

134134
numproblems=$((numproblems+$?))
135135

0 commit comments

Comments
 (0)