]> git.phdru.name Git - git-scripts.git/blob - svn/svn2git
Feat(submodules/remove): Add option `-c`
[git-scripts.git] / svn / svn2git
1 #! /bin/sh
2
3 if [ -z "$1" ]; then
4    echo "Usage: $0 svn_url [dir]" >&2
5    exit 1
6 fi
7
8 url="$1"
9
10 if [ ! -f authors.txt ]; then
11    echo "Run \"get-authors $1\" first" >&2
12    exit 2
13 fi
14
15 if [ -z "$2" ]; then
16    dir="`basename $url`"
17 else
18    dir="$2"
19 fi
20
21 if [ -z "$dir" ]; then
22    echo "Usage: $0 $url dir" >&2
23    exit 1
24 fi
25
26 # init + fetch
27 git svn clone "$url" --authors-file=authors.txt --prefix=svn/ --stdlayout "$dir" &&
28 cd "$dir" &&
29
30 # Convert branches and tags
31
32 # See http://blog.jessitron.com/2013/08/converting-from-svn-to-git.html
33
34 git for-each-ref --format="%(refname:short)" refs/remotes/svn |
35    sed 's#svn/##' | grep -v '^tags' |
36       while read aBranch; do git branch $aBranch svn/$aBranch || exit 1; done
37
38 # See http://thomasrast.ch/git/git-svn-conversion.html
39
40 git for-each-ref --format="%(refname:short)" refs/remotes/svn/tags/ |
41 while read tag; do
42     GIT_COMMITTER_DATE="`git log -1 --pretty=format:\"%ad\" \"$tag\"`" \
43     GIT_COMMITTER_EMAIL="`git log -1 --pretty=format:\"%ce\" \"$tag\"`" \
44     GIT_COMMITTER_NAME="`git log -1 --pretty=format:\"%cn\" \"$tag\"`" \
45     git tag -a -m "`git for-each-ref --format=\"%(contents)\" \"$tag\"`" \
46         "`echo \"$tag\" | sed 's#svn/tags/##'`" "$tag" || exit 1
47 done
48
49 # convert svn:ignore to .gitignore
50 git svn create-ignore &&
51 git commit -m "Add .gitignore"
52
53 # preserve authors.txt
54 cp -p ../authors.txt .git/info &&
55 git config --local --path svn.authorsfile .git/info/authors.txt
56
57 git svn gc &&
58 git gc --aggressive &&
59 echo "Cloned from $url using git-svn" >.git/description &&
60 exec `git var GIT_EDITOR` .git/description