Skip to content

Instantly share code, notes, and snippets.

@plamentotev
Last active April 20, 2020 13:30
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 plamentotev/b835dd62c74a3a5becd4c317b97403a4 to your computer and use it in GitHub Desktop.
Save plamentotev/b835dd62c74a3a5becd4c317b97403a4 to your computer and use it in GitHub Desktop.
🇬🇧 When Maven was migrated from SVN to Git the tags didn't pointed to the master, but to a parallel history. This script helped with creating new tags that point to master. 🇧🇬 При мигрирането на Maven от SVN към Git таговете сочеха не към основната история, а към нейни разклонения. Този скрипт помогна да се създадат нови тагове.
for d in plugins/maven-*; do
pushd "${d}" > /dev/null
for tag in $(git tag); do
commit_sha=$(git rev-list -n1 "refs/tags/${tag}")
commit_message=$(git show --quiet --pretty="format:%B" "${commit_sha}")
tree_sha=$(git show --quiet --pretty="format:%T" "${commit_sha}")
# checking if the tag is reachable from master so the script could be ran multiple times.
if $( git merge-base --is-ancestor "${tag}" master ) ; then
echo "${tag} is reachable from master. Skipping."
continue;
fi
if [[ ! ${commit_message} =~ git-svn ]] ; then
echo "${tag} does not point to an SVN commit and will not be modified"
continue
fi
candidate_commit_sha=$(git rev-list -n1 --grep "\[maven-release-plugin\] prepare release ${tag}$" master);
if [ -z ${candidate_commit_sha} ] ; then
echo "Looks like ${tag} is not released with the release plug-in. Skipping."
continue
fi
candidate_tree_sha=$(git show --quiet --pretty="format:%T" "${candidate_commit_sha}")
if [[ ${tree_sha} != ${candidate_tree_sha} ]] ; then
echo "${tag} - the commit created by the release plug-in does not have the same files as the tag. Skipping."
continue
fi
# This will change the tag date and author to the current date and git user
# As we're essentially recreating the tags I think this is ok.
# The release date and author are preserved in the release commit.
# The tag message will be changed to only the tag name.
# NOTE: Uncomment the following line to actually change the tags
#git tag -f -a -m "${tag}" "${tag}" "${candidate_commit_sha}" > /dev/null
done
popd > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment