Skip to content

Commit 86b31a6

Browse files
committed
refactor: avoid appending reports to merge commits
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: passed - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 2d82fb2 commit 86b31a6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tools/git/hooks/commit-msg

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,26 @@ lint() {
7676

7777
# Appends a report generated during the pre-commit hook.
7878
append_pre_commit_report() {
79-
# Check whether the commit message already contains a report (e.g., as may be the case when amending a commit message; git commit --amend):
79+
# Check whether the commit is a merge commit:
80+
head -n 1 "${commit_message}" | grep -q '^Merge branch';
81+
82+
# For merge commits, no need to append a report...
83+
if [[ "$?" -eq 0 ]]; then
84+
return 0
85+
fi
86+
87+
# Check whether the commit message already contains a report (e.g., as may be the case when amending a commit message via git commit --amend):
8088
grep -q 'type: pre_commit_static_analysis_report' "${commit_message}"
8189

82-
# Only append a report if the message doesn't contain an existing report...
83-
if [[ "$?" -ne 0 ]]; then
84-
echo '' >> "${commit_message}"
85-
cat "${pre_commit_report}" >> "${commit_message}"
90+
# If a message already includes a report, skip appending a report...
91+
if [[ "$?" -eq 0 ]]; then
92+
return 0
8693
fi
94+
95+
# Append the report:
96+
echo '' >> "${commit_message}"
97+
cat "${pre_commit_report}" >> "${commit_message}"
98+
8799
return 0
88100
}
89101

0 commit comments

Comments
 (0)