Skip to content

Commit

Permalink
check local branch is synchronised.
Browse files Browse the repository at this point in the history
print latest tags and commit hashes
rootminus0x1 committed Dec 31, 2024
1 parent ff62963 commit 56eecb8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions bin/git-tag
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ shift

TAG="$1"
this=$(basename $0)
error="$error:"
error="error:"

# Validate the tag format using a regular expression
if [[ ! $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -28,18 +28,20 @@ fi

# Ensure there are no uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
echo "$error there are uncommitted changes in the repository. Please commit or stash them before proceeding"
echo "$error there are uncommitted changes in the repository - commit or stash them and try again"
exit 1
fi

# Ensure the local branch (main) is synchronized with origin/main
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
echo "Error: The local main branch is not synchronized with origin/main - pull the latest changes and try again"
exit 1
fi

# Extract the major.minor version from the tag
MAJOR_MINOR="$(echo $TAG | grep -oE '^v[0-9]+\.[0-9]+')"
LATEST_TAG="${MAJOR_MINOR}-latest"

# Create the new tag for the main branch
git fetch origin main
git pull origin main

# Create the new version tag and push it
git tag "$TAG"
git push origin "$TAG"
@@ -50,6 +52,8 @@ git push origin -f "$LATEST_TAG"

echo "created tag $TAG and updated $LATEST_TAG to point to it"

git ls-remote --tags origin | grep -oE '[a-f0-9]{40}\srefs/tags/[^"]+' | awk '{print $1, $2}' | sed 's|refs/tags/||' | sort -t ' ' -k 2 -V | tail -n 3 | while read -r hash tag; do
echo "$hash $tag"
done
REMOTE_TAGS=$(git ls-remote --tags origin | sed 's|\s*refs/tags/| |')
echo $(git rev-parse main) "main (local)"
echo $(git rev-parse origin/main) "origin/main"
echo "$REMOTE_TAGS" | grep '\-latest'
echo "$REMOTE_TAGS" | grep -v '\-latest' | sed -n '1!G;h;$p' | head -n 2

0 comments on commit 56eecb8

Please sign in to comment.