Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FP-1544: Annotate Lightweight Tags #465

Closed
wants to merge 8 commits into from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*.pyo
__pycache__

# Shell
_git_annotate_existing_tags

# Project
/public/static
/public/media
Expand Down
58 changes: 58 additions & 0 deletions bin/git_annotate_existing_tags.sh
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script was eventually restored. It's available in main currently. Permalink for the v4.9.0 one.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh

# Bug: (2022-03-12) (for a commit after v3.15.0)
# Running `git describe` gave unexpected output.
# - expect: "v3.15.0-…-g…"
# - actual: "v3.7.0-…-g…"
# Why: 1. Most tags after (and before) v3.7.0 were not annotated. Similar:
# https://github.com/Reference-LAPACK/lapack/issues/123
# 2. Because GitHub uses lightweight tags. Feedback for GitHub:
# https://github.com/github/feedback/discussions/4924
# Fix: Run this script to retroactively annotate lightweight tags.
# (Note, this script also re-annotates annotated tags.)
wesleyboar marked this conversation as resolved.
Show resolved Hide resolved
# Alt: See answers to https://stackoverflow.com/q/21738647/11817077
# (More elegant but may not preserve all of tag message with new lines.)

# make output directory
OUTPUT_DIR='_git_annotate_existing_tags'
mkdir -p "$OUTPUT_DIR"

# define how to save current status of tag annotation
function save_tag_summary() {
local path=$1

echo "$(git tag --format='%(creatordate)%09%(refname:strip=2) %(taggerdate) %(contents)')" > $path
}

# define how to annotate tags (will also re-annotate tags)
function annotate() {
local tag=$1

# get data for tag (some is new for annotation, some must be preserved)
local date="$(echo $(git tag --format='%(creatordate)' --list $tag))"
local msg="$(git tag --format='%(contents)' --list $tag)"
local hash="$(git rev-list -n 1 $tag)"

# save message to file to preserve new lines
local msg_file_path="$OUTPUT_DIR/message.temp"
echo "$msg" > $msg_file_path

# tell the user what we will do
echo "Annotate tag $(printf "%9s" $tag) (commit ${hash:0:7}) with date \"$date\" and retain its message \"${msg:0:30}...\"."

# annotate
GIT_COMMITTER_DATE=$date \
git tag --annotate --force --file "$msg_file_path" "$tag" "$hash"

# clean up
rm $msg_file_path
}

# save current status to file for comparison
save_tag_summary "$OUTPUT_DIR/summary_before.temp"

# annotate each tag passed
for tag in "$@"; do annotate "$tag"; done

# save new status to file for comparison
save_tag_summary "$OUTPUT_DIR/summary_after.temp"