Skip to content

Commit 1867584

Browse files
committed
chore: add recipes for authoring Git commit messages
1 parent 95f0602 commit 1867584

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed

tools/make/lib/git/Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2023 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+
# DEPENDENCIES #
20+
21+
# Note: keep in alphabetical order...
22+
include $(TOOLS_MAKE_LIB_DIR)/git/commitizen.mk
23+
24+
25+
# RULES #
26+
27+
#/
28+
# Provides an interactive prompt for entering commit message information in accordance with project Git commit conventions.
29+
#
30+
# @example
31+
# make commit
32+
#/
33+
commit: $(NODE_MODULES)
34+
ifeq ($(GIT_COMMIT_PROMPT), commitizen)
35+
$(QUIET) NODE_PATH="$(NODE_PATH)" $(MAKE) -f $(this_file) commitizen-commit
36+
endif
37+
38+
.PHONY: commit
39+
40+
#/
41+
# Retries a previous commit entered using `make commit`.
42+
#
43+
# @example
44+
# make retry-commit
45+
#/
46+
retry-commit: $(NODE_MODULES)
47+
ifeq ($(GIT_COMMIT_PROMPT), commitizen)
48+
$(QUIET) NODE_PATH="$(NODE_PATH)" $(MAKE) -f $(this_file) commitizen-retry-commit
49+
endif
50+
51+
.PHONY: retry-commit

tools/make/lib/git/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Git
22+
23+
> Git commands.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
This directory contains [`make`][make] rules for working with Git.
30+
31+
</section>
32+
33+
<!-- /.intro -->
34+
35+
<!-- Usage documentation. -->
36+
37+
<section class="usage">
38+
39+
## Usage
40+
41+
```text
42+
Usage: make <command> [<ENV_VAR>=<value> <ENV_VAR>=<value> ...]
43+
```
44+
45+
### Commands
46+
47+
#### commit
48+
49+
Provides an interactive prompt for creating a Git commit message in accordance with the project's [Git style guide][stdlib-style-guides-git].
50+
51+
<!-- run-disable -->
52+
53+
```bash
54+
$ make commit
55+
```
56+
57+
#### retry-commit
58+
59+
Retries a previous commit created using `make commit`.
60+
61+
<!-- run-disable -->
62+
63+
```bash
64+
$ make retry-commit
65+
```
66+
67+
This is particularly useful a commit failed due to lint errors. An example workflow might proceed as follows:
68+
69+
<!-- run-disable -->
70+
71+
```bash
72+
# Stage changed files and attempt to commit the changes:
73+
$ git add . && make commit
74+
75+
# Suppose `make commit` fails due to lint errors, so we resolve the lint errors.
76+
77+
# Stage the changes and re-attempt the commit, without having to re-enter commit info:
78+
$ git add . && make retry-commit
79+
```
80+
81+
</section>
82+
83+
<!-- /.usage -->
84+
85+
<!-- Section to include notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
86+
87+
<section class="notes">
88+
89+
</section>
90+
91+
<!-- /.notes -->
92+
93+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
94+
95+
<section class="links">
96+
97+
[make]: https://www.gnu.org/software/make/
98+
99+
[stdlib-style-guides-git]: https://github.com/stdlib-js/stdlib/blob/develop/docs/style-guides/git
100+
101+
</section>
102+
103+
<!-- /.links -->

tools/make/lib/git/commitizen.mk

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2023 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 path to the [`commitzen`][1] executable.
22+
#
23+
# To install `commitzen`:
24+
#
25+
# ```bash
26+
# $ npm install commitzen
27+
# ```
28+
#
29+
# [1]: https://github.com/commitizen/cz-cli
30+
COMMITIZEN ?= $(BIN_DIR)/cz
31+
32+
33+
# RULES #
34+
35+
#/
36+
# Provides an interactive prompt for entering commit message information in accordance with project Git commit conventions.
37+
#
38+
# ## Notes
39+
#
40+
# - We have to temporarily move the `tsconfig` file, as `commitlint` (erroneously) attempts to use the file for compiling TypeScript.
41+
#
42+
# @private
43+
#
44+
# @example
45+
# make commitizen-commit
46+
#/
47+
commitizen-commit: $(NODE_MODULES) $(COMMITIZEN)
48+
$(QUIET) mv $(ROOT_DIR)/tsconfig.json $(ROOT_DIR)/tsconfig.json.tmp
49+
$(QUIET) NODE_PATH="$(NODE_PATH)" $(NODE) "$(COMMITIZEN)" || (mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json && exit 1)
50+
$(QUIET) mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json
51+
52+
.PHONY: commitizen-commit
53+
54+
#/
55+
# Retries a previous commit entered using Commitizen.
56+
#
57+
# ## Notes
58+
#
59+
# - We have to temporarily move the `tsconfig` file, as `commitlint` (erroneously) attempts to use the file for compiling TypeScript.
60+
#
61+
# @private
62+
#
63+
# @example
64+
# make commitizen-retry-commit
65+
#/
66+
commitizen-retry-commit: $(NODE_MODULES) $(COMMITIZEN)
67+
$(QUIET) mv $(ROOT_DIR)/tsconfig.json $(ROOT_DIR)/tsconfig.json.tmp
68+
$(QUIET) NODE_PATH="$(NODE_PATH)" $(NODE) "$(COMMITIZEN)" --retry || (mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json && exit 1)
69+
$(QUIET) mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json
70+
71+
.PHONY: commitizen-retry-commit

0 commit comments

Comments
 (0)