Skip to content

Commit b73a6e1

Browse files
committed
Added hook suite documentation
1 parent 49f1953 commit b73a6e1

File tree

1 file changed

+69
-26
lines changed

1 file changed

+69
-26
lines changed

docs/reference/hooks.md

+69-26
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,29 @@ comments: true
77
---
88
# Hooks
99

10-
- Each global configuration of `setup_hooks`, `pre_commit_hooks`, and `post_commit_hooks` is a list of commands run in a shell
11-
- Explanation of the context passed into the environment
12-
- Run in sequentially
10+
## Hook Suites
1311

14-
Order of operations
12+
A _hook suite_ is a list of _hooks_ to run sequentially. A _hook_ is either an individual shell command or an executable script.
1513

16-
- Run setup hooks
17-
- Increment version
18-
- Change files
19-
- Run pre-commit hooks
20-
- commit and tag
21-
- Run post-commit hooks
14+
There are three hook suites: _setup, pre-commit,_ and _post-commit._ During the version increment process this is the order of operations:
2215

23-
## Setup Hooks
16+
1. Run _setup_ hooks
17+
2. Increment version
18+
3. Change files
19+
4. Run _pre-commit_ hooks
20+
5. Commit and tag
21+
6. Run _post-commit_ hooks
22+
23+
!!! Note
24+
25+
Don't confuse the _pre-commit_ and _post-commit_ hook suites with Git pre- and post-commit hooks. Those hook suites are named for their adjacency to the commit and tag operation.
26+
27+
28+
## Configuration
29+
30+
Configure each hook suite with the `setup_hooks`, `pre_commit_hooks`, or `post_commit_hooks` keys.
31+
32+
Each suite takes a list of strings. The strings may be individual commands:
2433

2534
```toml title="Calling individual commands"
2635
[tool.bumpversion]
@@ -30,28 +39,35 @@ setup_hooks = [
3039
"git --version",
3140
"git config --list",
3241
]
42+
pre_commit_hooks = ["cat CHANGELOG.md"]
43+
post_commit_hooks = ["echo Done"]
3344
```
3445

35-
or
46+
or the path to an executable script:
3647

3748
```toml title="Calling a shell script"
3849
[tool.bumpversion]
3950
setup_hooks = ["path/to/setup.sh"]
51+
pre_commit_hooks = ["path/to/pre-commit.sh"]
52+
post_commit_hooks = ["path/to/post-commit.sh"]
4053
```
4154

42-
```bash title="path/to/setup.sh"
43-
#!/usr/bin/env bash
55+
!!! Note
4456

45-
git config --global user.email "[email protected]"
46-
git config --global user.name "Testing Git"
47-
git --version
48-
git config --list
49-
```
50-
### Environment
57+
You can make a script executable using the following steps:
58+
59+
1. Add a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) line to the top like `#!/bin/bash`
60+
2. Run `chmod u+x path/to/script.sh` to set the executable bit
61+
62+
## Hook Environments
5163

52-
- The existing OS environment is available
64+
Each hook has these environment variables set when executed.
5365

54-
#### Date and time fields
66+
### Inherited environment
67+
68+
All environment variables set before bump-my-version was run are available.
69+
70+
### Date and time fields
5571

5672
::: field-list
5773

@@ -61,9 +77,11 @@ git config --list
6177
`BVHOOK_UTCNOW`
6278
: The ISO-8601-formatted current local time in the UTC time zone.
6379

64-
#### Source code management fields
80+
### Source code management fields
81+
82+
!!! Note
6583

66-
These fields will only have values if the code is in a Git or Mercurial repository.
84+
These fields will only have values if the code is in a Git or Mercurial repository.
6785

6886
::: field-list
6987

@@ -83,7 +101,7 @@ These fields will only have values if the code is in a Git or Mercurial reposito
83101
: The current branch name, converted to lowercase, with non-alphanumeric characters removed and truncated to 20 characters. For example, `feature/MY-long_branch-name` would become `featuremylongbranchn`.
84102

85103

86-
#### Version fields
104+
### Current version fields
87105

88106
::: field-list
89107
`BVHOOK_CURRENT_VERSION`
@@ -93,4 +111,29 @@ These fields will only have values if the code is in a Git or Mercurial reposito
93111
: The current tag
94112

95113
`BVHOOK_CURRENT_<version component>`
96-
: Each version component defined by the [version configuration parsing regular expression](configuration/global.md#parse). The default configuration would have `current_major`, `current_minor`, and `current_patch` available.
114+
: Each version component defined by the [version configuration parsing regular expression](configuration/global.md#parse). The default configuration would have `BVHOOK_CURRENT_MAJOR`, `BVHOOK_CURRENT_MINOR`, and `BVHOOK_CURRENT_PATCH` available.
115+
116+
117+
### New version fields
118+
119+
!!! Note
120+
121+
These are not available in the _setup_ hook suite.
122+
123+
::: field-list
124+
`BVHOOK_NEW_VERSION`
125+
: The new version serialized as a string
126+
127+
`BVHOOK_NEW_TAG`
128+
: The new tag
129+
130+
`BVHOOK_NEW_<version component>`
131+
: Each version component defined by the [version configuration parsing regular expression](configuration/global.md#parse). The default configuration would have `BVHOOK_NEW_MAJOR`, `BVHOOK_NEW_MINOR`, and `BVHOOK_NEW_PATCH` available.
132+
133+
## Outputs
134+
135+
The `stdout` and `stderr` streams are echoed to the console if you pass the `-vv` option.
136+
137+
## Dry-runs
138+
139+
Bump my version does not execute any hooks during a dry run. With the verbose output option it will state which hooks it would have run.

0 commit comments

Comments
 (0)