diff options
Diffstat (limited to 'bin/git/git-svn-abandon-fix-refs')
-rwxr-xr-x | bin/git/git-svn-abandon-fix-refs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/bin/git/git-svn-abandon-fix-refs b/bin/git/git-svn-abandon-fix-refs new file mode 100755 index 0000000..c47405d --- /dev/null +++ b/bin/git/git-svn-abandon-fix-refs @@ -0,0 +1,63 @@ +#!/bin/sh + +# clean up working dir + +git update-ref -d master + +# create annotated tags out of svn tags +git for-each-ref --format='%(refname)' refs/remotes/svn/tags/* | while read tag_ref; do + tag=${tag_ref#refs/remotes/svn/tags/} + tree=$( git rev-parse "$tag_ref": ) + + # find the oldest ancestor for which the tree is the same + parent_ref="$tag_ref"; + while [ $( git rev-parse --quiet --verify "$parent_ref"^: ) = "$tree" ]; do + parent_ref="$parent_ref"^ + done + parent=$( git rev-parse "$parent_ref" ); + + # if this ancestor is in trunk then we can just tag it + # otherwise the tag has diverged from trunk and it's actually more like a + # branch than a tag + merge=$( git merge-base "refs/remotes/svn/trunk" $parent ); + if [ "$merge" = "$parent" ]; then + target_ref=$parent + else + echo "tag has diverged: $tag" + target_ref="$tag_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' "$tag_ref" | \ + perl -ne 'next if /^git-svn-id:/; $s++, next if /^\s*r\d+\@.*:.*\|/; s/^ // if $s; print' | \ + env GIT_COMMITTER_NAME="$( git show -s --pretty='format:%an' "$tag_ref" )" \ + GIT_COMMITTER_EMAIL="$( git show -s --pretty='format:%ae' "$tag_ref" )" \ + GIT_COMMITTER_DATE="$( git show -s --pretty='format:%ad' "$tag_ref" )" \ + git tag -a -F - "$tag" "$target_ref" + + git update-ref -d "$tag_ref" +done + +# create local branches out of svn branches +git for-each-ref --format='%(refname)' refs/remotes/svn/ | while read branch_ref; do + branch=${branch_ref#refs/remotes/svn/} + git branch "$branch" "$branch_ref" + git update-ref -d "$branch_ref" +done + +# rename 'trunk' to 'master' +git checkout trunk +git branch -M trunk master + +# remove merged branches +git for-each-ref --format='%(refname)' refs/heads | while read branch; do + git rev-parse --quiet --verify "$branch" || continue # make sure it still exists + git symbolic-ref HEAD "$branch" + git branch -d $( git branch --merged | grep -v '^\*' ) +done + +git checkout master + +# list possible merge commits to help create a grafts file +git log --pretty=one --all -E --grep='[mM]erge|\(orig r' + |