Skip to content

Commit 1a68e78

Browse files
committed
build: add make command to apply Git notes and fix file extension
1 parent 7295660 commit 1a68e78

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

tools/make/lib/git/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# Note: keep in alphabetical order...
2222
include $(TOOLS_MAKE_LIB_DIR)/git/commitizen.mk
23-
23+
include $(TOOLS_MAKE_LIB_DIR)/git/notes.mk
2424

2525
# RULES #
2626

tools/make/lib/git/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ $ git add . && make commit
7878
$ git add . && make retry-commit
7979
```
8080

81+
#### apply-git-notes
82+
83+
Applies Git notes from the `docs/git-notes` directory to their corresponding commits.
84+
85+
<!-- run-disable -->
86+
87+
```bash
88+
$ make apply-git-notes
89+
```
90+
91+
This is useful for fixing commit messages which contain errors or do not adhere to the project's [Git style guide][stdlib-style-guides-git] and to exclude certain commits from the changelog notes for specific packages.
92+
8193
</section>
8294

8395
<!-- /.usage -->

tools/make/lib/git/notes.mk

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2024 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
# Define the directory containing git notes:
22+
GIT_NOTES_DIR ?= $(ROOT_DIR)/docs/git-notes
23+
24+
# RULES #
25+
26+
#/
27+
# Applies Git notes from the `docs/git-notes` directory.
28+
#
29+
# ## Notes
30+
#
31+
# - This rule applies git notes where the file name (without the .txt extension) is the git commit hash and the content is the note.
32+
#
33+
# @example
34+
# make apply-git-notes
35+
#/
36+
apply-git-notes:
37+
$(QUIET) echo "Applying git notes..."
38+
$(QUIET) for note in $(GIT_NOTES_DIR)/*.txt; do \
39+
if [ -f "$$note" ]; then \
40+
commit_hash=$$(basename "$$note" .txt); \
41+
git notes add -f -F "$$note" "$$commit_hash" || echo "Failed to apply note for commit $$commit_hash"; \
42+
fi; \
43+
done
44+
$(QUIET) echo "Git notes application complete."
45+
46+
.PHONY: apply-git-notes

0 commit comments

Comments
 (0)