Skip to content

Commit 2d82fb2

Browse files
committed
chore: rename report and only append if no existing report in message
--- 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 a74169f commit 2d82fb2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tools/git/hooks/commit-msg

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

7777
# Appends a report generated during the pre-commit hook.
7878
append_pre_commit_report() {
79-
echo '' >> "${commit_message}"
80-
cat "${pre_commit_report}" >> "${commit_message}"
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):
80+
grep -q 'type: pre_commit_static_analysis_report' "${commit_message}"
81+
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}"
86+
fi
8187
return 0
8288
}
8389

tools/git/hooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ write_to_cache() {
124124
init_cache_file() {
125125
touch "${cache_file}"
126126
write_to_cache '---'
127-
write_to_cache 'type: git_hook_static_analysis_report'
127+
write_to_cache 'type: pre_commit_static_analysis_report'
128128
write_to_cache 'description: Results of running static analysis checks when committing changes.'
129129
write_to_cache 'report:'
130130
}

0 commit comments

Comments
 (0)