From 102265b4a7f34d7412fde8379d29a2f44630cfc4 Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Wed, 11 Dec 2024 15:50:09 +0900 Subject: [PATCH] tag.sh: only fetch origin remote, auto-increment last digit if there is an existing tag OTU1ZmY0NTUzNzBlMDllZDBlNDFjYjJjY2I0YTZlNDFlOTZiZjVmOQo= --- tag.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tag.sh b/tag.sh index dd57c33f6..65c20cc6f 100755 --- a/tag.sh +++ b/tag.sh @@ -16,22 +16,30 @@ fi echo -e "${YELLOW}Checking if branch is up to date...${NC}" changed=0 -git remote update && git status -uno | grep -q 'Your branch is behind' && changed=1 +git remote update origin && git status -uno | grep -q 'Your branch is behind' && changed=1 if [ $changed = 1 ]; then echo -e "${RED}Please git pull before tagging.${NC}" exit 1 fi -# get the current date in the format YY.MM.DD -DATE=$(date +%y.%-m.%-d) - -# create plain tag with .0 at end -TAG=$DATE.0 - # Ask user to confirm the commit and the tag name echo -e "${YELLOW}Current HEAD of master branch:${NC}" git log -1 --decorate echo + +# get the current date in the format YY.MM.DD +DATE=$(date +%y.%-m.%-d) + +# Check if the tag already exists and increment if necessary +COUNTER=0 +TAG=$DATE.$COUNTER +while git rev-parse "$TAG" >/dev/null 2>&1; do + # Increment the counter and recreate TAG with DATE + echo -e "${YELLOW}Tag $TAG already exists, incrementing.${NC}" + COUNTER=$((COUNTER + 1)) + TAG="$DATE.$COUNTER" +done +echo echo -e -n "${YELLOW}Tagging current HEAD of master with tag ${TAG}. Are you sure? (y/n): ${NC}" read -p "" -n 1 -r echo