🌐 AI搜索 & 代理 主页
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ repos:
rev: v1.16.3
hooks:
- id: zizmor
- repo: local
hooks:
- id: check-commit-prefix
stages: [prepare-commit-msg]
name: Check commit prefix
entry: scripts/check_commit_prefix.py
language: python
4 changes: 2 additions & 2 deletions scripts/backport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ REV=$1

TMPFILE=tmplog.tmp

# Cherry-pick the commit
git cherry-pick ${REV}
# Cherry-pick the commit, but skip hooks
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows what we want -- I normally want the hook to catch naive uses of git cherry-pick, so I have to skip the hook here (where a naive cherry-pick is done intentionally).

git -c core.hooksPath=/dev/null cherry-pick ${REV}
Comment on lines +22 to +23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurs to me this isn't windows-friendly, but we can cross that bridge later. Perhaps we would want to just replace the backport script entirely with a fleshed out prepare-commit-msg hook.


# Create new log message by modifying the old one
git log --pretty=format:"[${BRANCH_NAME}] %s%n%n%b%nBackport of ${REV} from main." HEAD^..HEAD \
Expand Down
22 changes: 22 additions & 0 deletions scripts/check_commit_prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python

# Install this prepare-commit-msg hook with
# pre-commit install --hook-type prepare-commit-msg
Comment on lines +3 to +4
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the install step.


import subprocess
import sys

with open(sys.argv[1], "r", encoding="utf-8") as f:
first_line = f.readline()

commit_msg_text = subprocess.run(
["git", "branch", "--show-current"],
capture_output=True,
).stdout.decode(encoding="utf-8")

stripped_branch_name = commit_msg_text.strip("stable/").strip()
if stripped_branch_name and stripped_branch_name[0].isnumeric():
expected_prefix = f"[{stripped_branch_name}] "
assert first_line.startswith(
expected_prefix
), f"Expected {first_line!r} to start with {expected_prefix!r}"
Loading