/
sync-svn-to-git.sh
executable file
·45 lines (34 loc) · 1.23 KB
/
sync-svn-to-git.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# TODO: detect current checked out branch/HEAD and return to it after completion.
die() {
echo "sync-svn-to-git died: $*"
exit 1
}
# The git master branch to which SVN has to be synced to.
gitmaster=master
# The branch that is used to interface with SVN through git-svn rebase and dcommit.
svnside=svn-sync/svn-side
# Pointer (on the git master branch) to the last synced commit.
gitside=svn-sync/git-side
# Temporary work branch pointers for porting the commits.
workstart=svn-sync/tmp-svn2git-start
workend=svn-sync/tmp-svn2git-end
# Handy for debugging
set -x
# Set pointer to last commit from current SVN branch.
# Note that we use this branch as sort of mutex.
git branch $workstart $svnside || die 'Could not create temporary working branch, maybe another sync is in progress?'
# Git-svn fetch and rebase.
git checkout $svnside
git svn rebase
# Create temporary work branch to be ported to git master.
git branch $workend $svnside
# Rebase work branch on top of git master.
git rebase --onto $gitside $workstart $workend
# Merge work branch in master
git checkout $gitmaster
git merge $workend
git branch -f $gitside $gitmaster
# Clean up temporary work branches (release mutex).
git branch -D $workstart
git branch -D $workend