Skip to content

Commit cb26765

Browse files
committed
docs: corrected Git hook example
1 parent fd12fcd commit cb26765

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ A tooling and language agnostic utility to calculate the next semantic version b
3535

3636
## Usage
3737
Conventional Commits Next Version calculates the next semantic version based on the Conventional Commits since the prior version.
38-
The range of commits start excusively from the commit specified by either the arguments `--from-commit-hash` or `--from-reference`, till inclusively of `HEAD`.
38+
The range of commits start exclusively from the commit specified by either the arguments `--from-commit-hash` or `--from-reference`, till inclusively of `HEAD`.
3939
Any commits in this range which conform to the Conventional Commits v1.0.0 specification are used to calculate the next Semantic Versioning, based upon the initial Semantic Versioning provided via the argument `--from-version`.
4040

4141
There are two modes of calculating the next semantic version, consecutive mode and batch mode.
@@ -195,17 +195,20 @@ conventional-commits-next-version-checking:
195195
An example `commit-msg` Git hook to check if a Rust projects semantic version needs increased because of the commit message.
196196

197197
```
198-
#!/bin/bash
198+
#!/usr/bin/env bash
199199
200-
COMMIT_MESSAGE=$(cat $1)
200+
set -o errexit
201+
set -o pipefail
202+
203+
commit_message=$(cat "${1}")
201204
202205
# Get current version in the commit to be made.
203-
COMMIT_VERSION=$(grep '^version = "[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"$' Cargo.toml | cut -d '"' -f 2)
206+
current_version=$(grep '^version = "[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"$' Cargo.toml | cut -d '"' -f 2)
204207
# Get latest version on the remote HEAD.
205-
HEAD_VERSION=$(git show remotes/origin/HEAD:Cargo.toml | grep '^version = "[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"$' | cut -d '"' -f 2)
208+
head_version=$(git show remotes/origin/HEAD:Cargo.toml | grep '^version = "[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"$' | cut -d '"' -f 2)
206209
207210
# Check current commits version vs expected because of the new commit's message.
208-
RUST_LOG=info /home/$USER/.cargo/bin/conventional_commits_next_version --from-commit-message "$COMMIT_MESSAGE" --from-version $HEAD_VERSION --current-version $COMMIT_VERSION
211+
echo "${commit_message}" | "/home/${USER}/.cargo/bin/conventional_commits_next_version" --from-stdin --from-version "${head_version}" --current-version "${current_version}"
209212
```
210213

211214

0 commit comments

Comments
 (0)