hooks:pre-push: Allow WIP commits on WIP branches

This commit is contained in:
2025-03-03 17:11:44 +01:00
parent 459453dc5e
commit 78464fdfb0

View File

@@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# A hook script to verify what is about to be pushed. Called by "git push" # A hook script to verify what is about to be pushed. Called by "git push"
# after it has checked the remote status, but before anything has been pushed. # after it has checked the remote status, but before anything has been pushed.
@@ -26,6 +26,11 @@ url="$2"
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0') zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
# look for WIP at beginning or end of branch name
git rev-parse --symbolic-full-name --abbrev-ref HEAD \
| grep -Eqi '^wip($|[^[:alpha:]])|(^|[^[:alpha:]])wip$'
is_wip_branch=$((! $?))
while read local_ref local_oid remote_ref remote_oid; do while read local_ref local_oid remote_ref remote_oid; do
[ "$local_oid" != "$zero" ] || continue [ "$local_oid" != "$zero" ] || continue
@@ -41,7 +46,7 @@ while read local_ref local_oid remote_ref remote_oid; do
pattern='^(WIP|(fixup|squash)!)' pattern='^(WIP|(fixup|squash)!)'
commits="$(git rev-list -E --oneline --grep "$pattern" "$range")" commits="$(git rev-list -E --oneline --grep "$pattern" "$range")"
if [ -n "$commits" ]; then if [ -n "$commits" ] && ((!is_wip_branch)); then
printf >&2 "$local_ref: Commits in progress:\n" printf >&2 "$local_ref: Commits in progress:\n"
printf >&2 "%s\n" "$commits" printf >&2 "%s\n" "$commits"
printf >&2 "Aborting push\n" printf >&2 "Aborting push\n"