]> git.phdru.name Git - git-scripts.git/commitdiff
Convert tags and branches
authorOleg Broytman <phd@phdru.name>
Thu, 10 Jul 2014 04:03:29 +0000 (08:03 +0400)
committerOleg Broytman <phd@phdru.name>
Thu, 10 Jul 2014 04:03:29 +0000 (08:03 +0400)
svn/clone

index 8e880c3aa5bd6d4cd86c4915baf5706894e7692b..b225f69e6ff3c7ce03997d523297b84ccd9e2b43 100755 (executable)
--- a/svn/clone
+++ b/svn/clone
@@ -24,14 +24,27 @@ if [ -z "$dir" ]; then
 fi
 
 # init + fetch
-git svn clone "$url" --authors-file=authors.txt --stdlayout "$dir" &&
+git svn clone "$url" --authors-file=authors.txt --prefix=svn/ --stdlayout "$dir" &&
 cd "$dir" &&
 
-# fix references
-#cp -rf .git/refs/remotes/tags/* .git/refs/tags/ &&
-#rm -rf .git/refs/remotes/tags
-#cp -rf .git/refs/remotes/* .git/refs/heads/ &&
-#rm -rf .git/refs/remotes
+# Convert tags and branches
+
+# See http://blog.jessitron.com/2013/08/converting-from-svn-to-git.html
+
+git for-each-ref --format="%(refname:short)" refs/remotes/svn |
+   sed 's#svn/##' | grep -v '^tags' |
+      while read aBranch; do git branch $aBranch svn/$aBranch || exit 1; done
+
+# See http://thomasrast.ch/git/git-svn-conversion.html
+
+git for-each-ref --format="%(refname:short)" refs/remotes/svn/tags/ |
+while read tag; do
+    GIT_COMMITTER_DATE="`git log -1 --pretty=format:\"%ad\" \"$tag\"`" \
+    GIT_COMMITTER_EMAIL="`git log -1 --pretty=format:\"%ce\" \"$tag\"`" \
+    GIT_COMMITTER_NAME="`git log -1 --pretty=format:\"%cn\" \"$tag\"`" \
+    git tag -a -m "`git for-each-ref --format=\"%(contents)\" \"$tag\"`" \
+        "`echo \"$tag\" | sed 's#svn/tags/##'`" "$tag" || exit 1
+done
 
 # convert svn:ignore to .gitignore
 git svn create-ignore &&