-
Notifications
You must be signed in to change notification settings - Fork 3
/
svn-to-git
executable file
·62 lines (53 loc) · 2.28 KB
/
svn-to-git
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Fail on an error
set -e
absdir() {
echo "$(cd "$(dirname "$1")" && pwd)/"
}
dir=${1:-sakai}
prog_dir=$(absdir $0)
# Use trunk as we need to merge in a module called master
git clone --single-branch --branch trunk ./repos/sakai.git $dir
cd $dir
$prog_dir/update-authors.sh trunk
export TMPFILE=`mktemp /tmp/$(basename $0).XXXXXX` || exit 1
cat .externals| grep -v '^#' | tr -s '\n'| cut -d' ' -f1 |sort|\
grep -v metaobj |\
grep -v warehouse |\
grep -v osp |\
while read directory
do echo $directory
# Samigo doesn't match it's directory and repository name.
module=$(echo $directory | sed 's/samigo/sam/')
# Add a remote for the submodule
git remote add $module-sakai ../repos/$module.git
# Fetch the trunk branch from the remote
git fetch $module-sakai trunk
# Create a branch todo work on based on the trunk branch from the remote
git branch -f tmp-$module $module-sakai/trunk
# List of all files no longer related to current checkout
#comm -23 \
# <(git log --pretty=format: --name-only --diff-filter=A tmp-$module | sort -u) \
# <(git ls-tree -r --name-only tmp-$module | xargs -n 1 git blame -f tmp-$module -- | awk '{print $2;}' | sort -u ) \
# >$TMPFILE
# Remove all those files from commits
# git filter-branch -f --index-filter 'cat $TMPFILE | xargs git rm -f --cached --ignore-unmatch > /dev/null' --prune-empty -- tmp-$module
# Re-write history so it always looks like it was in that folder
# This is slow....
# git filter-branch -f --prune-empty --tree-filter "$prog_dir/move-to-folder $directory" -- tmp-$module
# This is much faster as we just mess with the index.
git filter-branch -f --index-filter "
git ls-files -s | sed \"s/ / $directory\//\" |
GIT_INDEX_FILE=\$GIT_INDEX_FILE.new git update-index --index-info &&
# If nothing changed then the file isn't created so we need to check first
(test -f \$GIT_INDEX_FILE.new && mv \$GIT_INDEX_FILE.new \$GIT_INDEX_FILE; true)
" tmp-$module
$prog_dir/update-authors.sh tmp-$module
# Rename our working branch to be the original
git branch -M tmp-$module $module
git for-each-ref --format="%(refname)" refs/original/ |\
xargs -n 1 git update-ref -d
git merge --no-commit $module
git commit -m "Subtree $module merged"
done
#git prune