Skip to content

Commit

Permalink
tag.sh: only fetch origin remote, auto-increment last digit if there …
Browse files Browse the repository at this point in the history
…is an existing tag

<rikaitan.link>OTU1ZmY0NTUzNzBlMDllZDBlNDFjYjJjY2I0YTZlNDFlOTZiZjVmOQo=</rikaitan.link>
  • Loading branch information
jason-ojisan committed Dec 12, 2024
1 parent da1ae0f commit 102265b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 102265b

Please sign in to comment.