Merge branch 'master' of ssh://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin-scripts.git] / git-migration / migrate.sh
blob652ef75309f7947754ac58c9248fb591f18577d1
1 #!/bin/sh
3 # Verbose
4 set -x
6 # Exit on failure
7 set -e
9 if [ ! -d pma-svn-git ] ; then
10 # Init repository on first run
11 mkdir pma-svn-git
12 cd pma-svn-git
13 git svn init -s --no-metadata https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin
14 git config svn.authorsfile ../svn2git-authors
15 else
16 cd pma-svn-git
19 # Fetch revisions
20 git svn fetch --fetch-all
22 # Back to top level directory
23 cd ..
25 # Create working copy of the clone (we will modify it)
26 rm -rf pma-svn-git-work
27 cp -a pma-svn-git pma-svn-git-work
29 # Make local tags and branches
30 cd pma-svn-git-work
32 # Proper email address
33 git config --add user.email michal@cihar.com
35 # Tags
36 git branch -r | sed -rne 's, *tags/([^@]+)$,\1,p' | grep 'RELEASE\|STABLE\|TESTING' | while read tag ; do
37 git tag -a $tag -m "Imported SVN tag for $tag" "tags/${tag}^"
38 done
40 # Branches
41 git branch -r | grep -v ' *tags/' | grep 'QA_[0-9_]*$\|MAINT_[0-9_]*$' | while read branch ; do
42 git branch $branch $branch
43 done
45 # First connect orphan MAINT to QA
46 for branch in `git branch | grep MAINT_` ; do
47 masterbranch=`echo $branch | sed 's/MAINT_/QA_/; s/_[0-9]*$//'`
48 olddate="`git log $branch | grep '^Date' | tail -n 1 | sed 's/Date: *//'`"
49 masterdate="`git log $masterbranch | grep '^Date' | tail -n 1 | sed 's/Date: *//'`"
50 echo "$branch: $olddate / $masterdate"
51 if [ "$masterdate" = "$olddate" ] ; then
52 continue
54 echo "Branch $branch is outdated!"
55 oldtail="`git log $branch | grep '^commit' | tail -n 1 | sed 's/commit *//'`"
56 echo $masterbranch
57 masterpoint="`git log --before="$olddate" $masterbranch | grep '^commit' | head -n 1 | sed 's/commit *//'`"
58 echo "Will point $oldtail to $masterpoint"
59 git checkout $branch
60 git filter-branch -f --tag-name-filter cat --parent-filter "test \$GIT_COMMIT = $oldtail && echo '-p $masterpoint' || cat" HEAD
61 git checkout master
62 done
64 # Now connect orphan QA to master
65 for branch in `git branch | grep QA_` ; do
66 olddate="`git log $branch | grep '^Date' | tail -n 1 | sed 's/Date: *//'`"
67 echo "$branch: $olddate"
68 if [ "Thu May 3 17:25:09 2001 +0000" = "$olddate" ] ; then
69 continue
71 echo "Branch is outdated!"
72 oldtail="`git log $branch | grep '^commit' | tail -n 1 | sed 's/commit *//'`"
73 masterpoint="`git log --before="$olddate" master | grep '^commit' | head -n 1 | sed 's/commit *//'`"
74 echo "Will point $oldtail to $masterpoint"
75 childfilter=`echo $branch | sed 's/QA_/MAINT_/'`
76 git filter-branch -f --tag-name-filter cat --parent-filter "test \$GIT_COMMIT = $oldtail && echo '-p $masterpoint' || cat" -- --all
77 done
79 # Back to top level directory
80 cd ..
82 # Prepare separate repositories
83 rm -rf repos
84 mkdir repos
85 cd repos
87 # Clone and filter all top level dirs
88 for repo in data history localized_docs phpMyAdmin planet scripts themes website ; do
89 git clone ../pma-svn-git-work $repo
90 cd $repo
91 if [ $repo = phpMyAdmin -o $repo = themes ] ; then
92 for branch in `git branch -r | grep 'QA_[0-9_]*$\|MAINT_[0-9_]*$'` ; do
93 git branch `basename $branch` $branch
94 done
96 git config --add user.email michal@cihar.com
97 git filter-branch --subdirectory-filter $repo --tag-name-filter cat -- --all
98 cd ..
99 done