commit 265bf1049566d23eb0e44e718746619722e42fc9 Author: Ching Date: Mon May 13 16:52:57 2024 +0800 feat: 增加 post-commit 钩子;增加 README diff --git a/README.md b/README.md new file mode 100644 index 0000000..98f27e9 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +### post-commit +Script to ensure a tag for the current month exists. +每次提交时,检查是否存在当前月份的tag,如果不存在则创建一个。 + +#### usage +```shell +$ cp /path/to/your/git/hooks/post-commit /path/to/your/git/repo/.git/hooks/ +``` diff --git a/post-commit b/post-commit new file mode 100644 index 0000000..6cd3916 --- /dev/null +++ b/post-commit @@ -0,0 +1,21 @@ +#!/bin/sh +# Script to ensure a tag for the current month exists + +# Get the current year and month +YEAR_MONTH=$(date +%Y%m) + +# Format the tag as v{year}{month} +TAG_NAME="v$YEAR_MONTH" + +# Check if the tag already exists +if ! git rev-parse -q --verify "refs/tags/$TAG_NAME" >/dev/null; then + echo "Creating new tag for this month: $TAG_NAME" + # Create the tag + git tag -a "$TAG_NAME" -m "Monthly tag for $TAG_NAME" + # Optionally, you can push the tag to a remote repository + git push origin "$TAG_NAME" +else + echo "Tag for this month already exists: $TAG_NAME" +fi + +