-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathretag.sh
More file actions
executable file
·70 lines (60 loc) · 1.78 KB
/
Copy pathretag.sh
File metadata and controls
executable file
·70 lines (60 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Script to delete and recreate a git tag on the latest commit
# Usage: ./retag.sh <tag-name> [commit-message]
# Check if a tag name is provided
if [ -z "$1" ]; then
echo "Usage: ./retag.sh <tag-name> [commit-message]"
echo "Example: ./retag.sh v1.8.0"
echo "Example: ./retag.sh v1.8.0 \"Release 1.8.0\""
exit 1
fi
TAG_NAME=$1
COMMIT_MESSAGE=${2:-"Release $TAG_NAME"}
echo "========================================"
echo "Re-tagging: $TAG_NAME"
echo "Message: $COMMIT_MESSAGE"
echo "========================================"
# Check if tag exists locally
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Deleting local tag: $TAG_NAME"
git tag -d "$TAG_NAME"
else
echo "Local tag $TAG_NAME does not exist, skipping local deletion"
fi
# Check if tag exists on remote
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then
echo "Deleting remote tag: $TAG_NAME"
git push origin ":refs/tags/$TAG_NAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to delete remote tag"
exit 1
fi
else
echo "Remote tag $TAG_NAME does not exist, skipping remote deletion"
fi
# Get the latest commit
LATEST_COMMIT=$(git log -1 --oneline)
echo ""
echo "Latest commit: $LATEST_COMMIT"
echo ""
# Create new annotated tag
echo "Creating new tag: $TAG_NAME"
git tag -a "$TAG_NAME" -m "$COMMIT_MESSAGE"
if [ $? -ne 0 ]; then
echo "Error: Failed to create tag"
exit 1
fi
# Push the new tag
echo "Pushing tag to origin: $TAG_NAME"
git push origin "$TAG_NAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to push tag"
exit 1
fi
echo ""
echo "========================================"
echo "✓ Successfully re-tagged $TAG_NAME"
echo "========================================"
echo ""
git tag -l -n1 "$TAG_NAME"
git log --oneline -1 "$TAG_NAME"