diff --git a/docs/internals/contributing/committing-code.txt b/docs/internals/contributing/committing-code.txt index 2a41fe60cfe9..8bd3fc4c3ae8 100644 --- a/docs/internals/contributing/committing-code.txt +++ b/docs/internals/contributing/committing-code.txt @@ -256,13 +256,13 @@ The ``scripts/prepare_commit_msg.py`` Python script can be installed as a ``prepare-commit-msg`` git hook. It automatically adds the ``[A.B.x]`` prefix to the subject line, appends ``Backport of from main.`` to the commit body, and ensures the subject line ends with a period, even when the -cherry-pick produces conflicts. To install it, create an executable file -``.git/hooks/prepare-commit-msg`` containing: +cherry-pick produces conflicts. Copy the script from the main branch, and +install it as the hook: .. code-block:: sh - #!/bin/sh - exec python scripts/prepare_commit_msg.py "$@" + cp scripts/prepare_commit_msg.py .git/hooks/prepare-commit-msg + chmod +x .git/hooks/prepare-commit-msg Once installed, a plain ``git cherry-pick `` on a stable branch is sufficient; the hook handles the message formatting in all cases. diff --git a/scripts/prepare_commit_msg.py b/scripts/prepare_commit_msg.py index bcb5b5faf77f..65f4ac2ab5e6 100755 --- a/scripts/prepare_commit_msg.py +++ b/scripts/prepare_commit_msg.py @@ -11,11 +11,13 @@ - Adds "Backport of from main." when cherry-picking. To install: - 1. Ensure the folder `.git/hooks` exists. - 2. Create an executable file `.git/hooks/prepare-commit-msg` with content: + 1. Check out a trusted branch (main). + 2. Copy this script into the hooks directory: -#!/bin/sh -exec python scripts/prepare_commit_msg.py "$@" +cp scripts/prepare_commit_msg.py .git/hooks/prepare-commit-msg +chmod +x .git/hooks/prepare-commit-msg + +Repeat the installation from main to update the hook. """