summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/mageia-reset-and-import.sh37
1 files changed, 34 insertions, 3 deletions
diff --git a/scripts/mageia-reset-and-import.sh b/scripts/mageia-reset-and-import.sh
index 8a301c3..e7787cc 100755
--- a/scripts/mageia-reset-and-import.sh
+++ b/scripts/mageia-reset-and-import.sh
@@ -321,10 +321,41 @@ git push origin master 'refs/remotes/*:refs/heads/*'
pushd ../$SOFTWARE.git
git branch -D trunk
git branch -D origin/master
+
+# Tagging logic inspired by https://github.com/nothingmuch/git-svn-abandon/blob/master/git-svn-abandon-fix-refs
git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 | \
- while read ref; do
- git tag "$ref" "refs/heads/tags/$ref"
- git branch -D "tags/$ref"
+ while read tag; do
+ ref="refs/heads/tags/$tag"
+ refsha1=$(git rev-parse "$ref":)
+
+ # Find the oldest ancestor for which the tree is the same
+ parentref="$ref"
+ while [ $(git rev-parse --quiet --verify "$parentref"^:) = "$refsha1" ]; do
+ parentref="$parentref"^
+ done
+ parent=$(git rev-parse "$parentref")
+
+ # If this ancestor is in master then we can just tag it
+ # otherwise the tag has diverged from master and it's actually more like a
+ # branch than a tag
+ merge=$(git merge-base master $parent)
+ if [ "$merge" = "$parent" ]; then
+ targetref=$parent
+ else
+ targetref="$ref"
+ fi
+
+ # create an annotated tag based on the last commit in the tag, and delete the "branchy" ref for the tag
+ git show -s --pretty='format:%s%n%n%b' "$ref" | \
+ env GIT_COMMITTER_NAME="$(git show -s --pretty='format:%an' "$ref")" \
+ GIT_COMMITTER_EMAIL="$(git show -s --pretty='format:%ae' "$ref")" \
+ GIT_COMMITTER_DATE="$(git show -s --pretty='format:%ad' "$ref")" \
+ GIT_AUTHOR_NAME="$(git show -s --pretty='format:%an' "$ref")" \
+ GIT_AUTHOR_EMAIL="$(git show -s --pretty='format:%ae' "$ref")" \
+ GIT_AUTHOR_DATE="$(git show -s --pretty='format:%ad' "$ref")" \
+ git tag -a -F - "$tag" "$targetref"
+
+ git update-ref -d "$ref"
done
git gc --aggressive