Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/wiki
Submodule wiki updated from 27f2dc to 778158
16 changes: 13 additions & 3 deletions resources/git-hooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ elif [ -f "${DEVTOOLS_GRUMPHP_CONFIG}" ]; then
fi

# Run GrumPHP
if [ -n "${GRUMPHP_CONFIG_FILE}" ]; then
printf "%s\n" "${DIFF}" | exec 'vendor/bin/grumphp.phar' '--config' "${GRUMPHP_CONFIG_FILE}" 'git:commit-msg' "--git-user=$GIT_USER" "--git-email=$GIT_EMAIL" "$COMMIT_MSG_FILE"
if [ -x "vendor/bin/grumphp" ]; then
GRUMPHP_COMMAND='vendor/bin/grumphp'
elif [ -x "vendor/bin/grumphp.phar" ]; then
GRUMPHP_COMMAND='vendor/bin/grumphp.phar'
else
GRUMPHP_COMMAND='grumphp'
fi

printf "%s\n" "${DIFF}" | exec 'vendor/bin/grumphp.phar' 'git:commit-msg' "--git-user=$GIT_USER" "--git-email=$GIT_EMAIL" "$COMMIT_MSG_FILE"
if [ -n "${GRUMPHP_COMMAND}" ]; then
if [ -n "${GRUMPHP_CONFIG_FILE}" ]; then
printf "%s\n" "${DIFF}" | exec "${GRUMPHP_COMMAND}" '--config' "${GRUMPHP_CONFIG_FILE}" 'git:commit-msg' "--git-user=$GIT_USER" "--git-email=$GIT_EMAIL" "$COMMIT_MSG_FILE"
else
printf "%s\n" "${DIFF}" | exec "${GRUMPHP_COMMAND}" 'git:commit-msg' "--git-user=$GIT_USER" "--git-email=$GIT_EMAIL" "$COMMIT_MSG_FILE"
fi
fi
16 changes: 13 additions & 3 deletions resources/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ elif [ -f "${DEVTOOLS_GRUMPHP_CONFIG}" ]; then
fi

# Run GrumPHP
if [ -n "${GRUMPHP_CONFIG_FILE}" ]; then
printf "%s\n" "${DIFF}" | exec 'vendor/bin/grumphp.phar' '--config' "${GRUMPHP_CONFIG_FILE}" 'git:pre-commit' '--skip-success-output'
if [ -x "vendor/bin/grumphp" ]; then
GRUMPHP_COMMAND='vendor/bin/grumphp'
elif [ -x "vendor/bin/grumphp.phar" ]; then
GRUMPHP_COMMAND='vendor/bin/grumphp.phar'
else
GRUMPHP_COMMAND='grumphp'
fi

printf "%s\n" "${DIFF}" | exec 'vendor/bin/grumphp.phar' 'git:pre-commit' '--skip-success-output'
if [ -n "${GRUMPHP_COMMAND}" ]; then
if [ -n "${GRUMPHP_CONFIG_FILE}" ]; then
printf "%s\n" "${DIFF}" | exec "${GRUMPHP_COMMAND}" '--config' "${GRUMPHP_CONFIG_FILE}" 'git:pre-commit' '--skip-success-output'
fi

printf "%s\n" "${DIFF}" | exec "${GRUMPHP_COMMAND}" 'git:pre-commit' '--skip-success-output'
Comment on lines +36 to +40
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid unconditional second pre-commit GrumPHP execution

After the configured invocation runs, the script always falls through to a second git:pre-commit call without --config. In environments where /bin/sh executes pipeline segments in subshells (common with dash/bash), the first exec does not terminate the parent script, so this second call still runs and can fail when the default config is absent (a typical global-install case), causing commits to be blocked even though the configured run succeeded.

Useful? React with 👍 / 👎.

fi
4 changes: 1 addition & 3 deletions src/Config/ECSConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ final class ECSConfig
];

/**
* @var array{psr12: bool, common: bool, symplify: bool, strict: bool, cleanCode: bool} the prepared ECS sets applied by default
* @var array{psr12: bool, common: bool, symplify: bool, cleanCode: bool} the prepared ECS sets applied by default
*/
public const array DEFAULT_PREPARED_SETS = [
'psr12' => true,
'common' => true,
'symplify' => true,
'strict' => true,
'cleanCode' => true,
];

Expand Down Expand Up @@ -154,7 +153,6 @@ public static function applyDefaultRulesAndSets(ECSConfigBuilder $config): ECSCo
psr12: self::DEFAULT_PREPARED_SETS['psr12'],
common: self::DEFAULT_PREPARED_SETS['common'],
symplify: self::DEFAULT_PREPARED_SETS['symplify'],
strict: self::DEFAULT_PREPARED_SETS['strict'],
cleanCode: self::DEFAULT_PREPARED_SETS['cleanCode'],
);

Expand Down
6 changes: 6 additions & 0 deletions tests/GitHooks/PackagedHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public function packagedPreCommitHookWillPreferProjectConfigAndFallbackToTheMana
'DEVTOOLS_GRUMPHP_CONFIG=' . HookContentRenderer::MANAGED_GRUMPHP_CONFIG_PLACEHOLDER,
$contents,
);
self::assertStringContainsString('if [ -x "vendor/bin/grumphp" ]; then', $contents);
self::assertStringContainsString("GRUMPHP_COMMAND='vendor/bin/grumphp'", $contents);
self::assertStringContainsString('printf "%s\n" "${DIFF}" | exec "${GRUMPHP_COMMAND}"', $contents);
self::assertStringContainsString("'--config' \"\${GRUMPHP_CONFIG_FILE}\" 'git:pre-commit'", $contents);
}

Expand All @@ -58,6 +61,9 @@ public function packagedCommitMsgHookWillPreferProjectConfigAndFallbackToTheMana
'DEVTOOLS_GRUMPHP_CONFIG=' . HookContentRenderer::MANAGED_GRUMPHP_CONFIG_PLACEHOLDER,
$contents,
);
self::assertStringContainsString('if [ -x "vendor/bin/grumphp" ]; then', $contents);
self::assertStringContainsString("GRUMPHP_COMMAND='vendor/bin/grumphp'", $contents);
self::assertStringContainsString('printf "%s\n" "${DIFF}" | exec "${GRUMPHP_COMMAND}"', $contents);
self::assertStringContainsString("'--config' \"\${GRUMPHP_CONFIG_FILE}\" 'git:commit-msg'", $contents);
}
}