Skip to content

Instantly share code, notes, and snippets.

@tregusti
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tregusti/182a2133ca39b190b0b9 to your computer and use it in GitHub Desktop.
Save tregusti/182a2133ca39b190b0b9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Removes ALL(!!!) tags on the remote origin. Run this when the tags are as they should locally.
# Then push all tags with `git push --tags`
git fetch --tags
git for-each-ref --shell --format="name=%(refname);" 'refs/tags' | \
while read entry
do
eval "$entry"
git push --delete origin "$name"
done
#!/usr/bin/env bash
# This script removes all tags with "glenn" in the name. "glenn" is a temp prefix for tag clean up.
# This is a script to revert the result of `re-tag-all.sh` `rename-glenn.sh`.
get_tag_name() {
echo "$1" | sed 's/refs\/tags\///'
}
git for-each-ref --shell --format="name=%(refname);" 'refs/tags' | \
while read entry
do
eval "$entry"
tagname=$(get_tag_name $name)
if [[ "$name" =~ glenn ]]; then
git tag -d $(get_tag_name $name)
fi
done
#!/usr/bin/env bash
# This script removes all tags without "glenn" in the name. "glenn" is a temp prefix for tag clean up.
# This will be used after `re-tag-all.sh` and before `rename-glenn.sh`.
get_tag_name() {
echo "$1" | sed 's/refs\/tags\///'
}
git for-each-ref --shell --format="name=%(refname);" 'refs/tags' | \
while read entry
do
eval "$entry"
tagname=$(get_tag_name $name)
if [[ ! "$name" =~ glenn ]]; then
git tag -d $(get_tag_name $name)
fi
done
#!/usr/bin/env bash
# This script find all versioned branches with various naming formats, and creates an annotated tag `glenn/<version>`
# It keeps all committer/author information
get_version() {
echo $(echo "$1" | sed 's/[^\.0-9]//g')
}
get_tag_name() {
echo "$1" | sed 's/refs\/tags\///'
}
git for-each-ref --shell --format="\
type=%(objecttype); \
sha=%(*objectname); \
name=%(refname);\
taggername=%(authorname);\
taggeremail=%(authoremail);\
authorname=%(*authorname);\
authoremail=%(*authoremail);\
taggerdate=%(taggerdate:iso8601);\
commiterdate=%(committerdate:iso8601)\
" 'refs/tags' | \
while read entry
do
eval "$entry"
tagname=$(get_tag_name $name)
version=$(get_version "$name")
if [[ "$type" == "tag" ]]; then
# Annotated tag
date="$taggerdate"
commitref="$sha"
else
# Light weight tag
date="$commiterdate"
commitref="$tagname"
fi
if [ "$version" ]; then
if [[ "$version" == "0.1.49" ]]; then
# special treatment for bad tagging
version="1.0.49"
fi
authorname="$authorname$taggername"
authoremail="$authoremail$taggeremail"
printf "Tag %-6s: %-20s @ %s\n" "$version" "$authorname" "$date"
# Try to tag, if it fails it is because of dupe tag so try again with added suffix
GIT_COMMITTER_DATE="$date" \
GIT_COMMITTER_NAME="$authorname" \
GIT_COMMITTER_EMAIL="$authoremail" \
git tag -a "glenn/$version" "$commitref" -m "CLEANUP: Tag version $version" 2> /dev/null || \
GIT_COMMITTER_DATE="$date" \
GIT_COMMITTER_NAME="$authorname" \
GIT_COMMITTER_EMAIL="$authoremail" \
git tag -a "glenn/${version}-duplicate" "$commitref" -m "CLEANUP: Tag duplicate version $version"
fi
done
#!/usr/bin/env bash
# Last step script. To rename all temp named `glenn/<version>` tags to `version/<version>`
get_version() {
echo $(echo "$1" | sed 's#.*/##')
}
get_tag_name() {
echo "$1" | sed 's/refs\/tags\///'
}
PREFIX="version"
git for-each-ref --shell --format="\
name=%(refname);\
sha=%(*objectname); \
taggername=%(taggername);\
taggeremail=%(taggeremail);\
taggerdate=%(taggerdate:iso8601);\
" 'refs/tags' | \
while read entry
do
eval "$entry"
tagname=$(get_tag_name $name)
version=$(get_version "$name")
if [[ "$tagname" =~ glenn ]]; then
echo "Create $PREFIX/$version $taggername $taggerdate"
GIT_COMMITTER_DATE="$taggerdate" \
GIT_COMMITTER_NAME="$taggername" \
GIT_COMMITTER_EMAIL="$taggeremail" \
git tag -a "$PREFIX/$version" "$sha" -m "CLEANUP: Tag version $version" && \
git tag -d "$tagname"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment