Skip to content

Commit 8377731

Browse files
Merge pull request #11 from Kpler/fix-linearity
fix: configure target branch
2 parents a9c284d + bce3c99 commit 8377731

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,29 @@ Some out-of-the-box hooks for [pre-commit](https://github.com/pre-commit/pre-com
77

88
Add this to your `.pre-commit-config.yaml`
99

10+
```yaml
1011
- repo: https://github.com/Kpler/kp-pre-commit-hooks.git
1112
rev: v0.0.7 # Use the ref you want to point at
1213
hooks:
1314
- id: check-branch-linearity
1415
- id: check-branch-name
1516
- id: no-ephemeral-links
1617
exclude: '\.md$'
18+
```
1719
1820
### Hooks available
1921
2022
#### `check-branch-linearity`
21-
Simply check that your branch doesn't not contain any merge compare to `master` or `main` branch.
23+
Simply check that your branch doesn't not contain any merge compare to a target branch, `master` by default.
2224
It's a pre-push hook and will always run
2325

26+
To configure the target branch:
27+
```yaml
28+
hooks:
29+
- id: check-branch-linearity
30+
args: [targetbranch]
31+
```
32+
2433
#### `check-branch-name`
2534
Check that branch name is less than 70 characters
2635
It's a pre-push hook and will always run

git-branch-linearity.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/sh
22

3-
git fetch origin main:refs/remotes/origin/main 2> /dev/null
4-
if [ $? -eq 0 ]; then TARGET_BRANCH="main"; else TARGET_BRANCH="master"; fi
3+
# Use parameter passed to the script or default to master
4+
TARGET_BRANCH="${1:-master}"
5+
56
echo "Target branch: $TARGET_BRANCH"
7+
git fetch origin $TARGET_BRANCH 2> /dev/null
68

79
out=$(git log origin/${TARGET_BRANCH}..HEAD --merges --oneline)
810
exit_status=$?

0 commit comments

Comments
 (0)