public
Description: Automate common steps when getting setup with git-svn.
Homepage: http://effectif.com/2008/4/24/easy-git-svn-for-rails
Clone URL: git://github.com/gma/git-me-up.git
Search Repo:
git-me-up / git-me-up
100755 127 lines (104 sloc) 3.035 kb
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
#
# git-me-up was written to automate the creation of a local git repo for a
# Rails app that is hosted in Subversion. See the README for more details.
#
# Synopsis: git-me-up <subversion-repo> <local-git-repo>
#
# Author: Graham Ashton <graham@effectif.com>
 
BRANCH="${BRANCH:-work}"
 
## Functions
 
log()
{
    echo "$(basename $0): $1"
}
 
usage()
{
    echo "Usage: $(basename $0) <svn-repository> <local-dir>" 1>&2
    exit 1
}
 
check_for_local_dir()
{
    local dir="$1"
    if [ -e "$dir" ]; then
echo "$(basename $0): ERROR: $dir already exists - please move it!" 1>&2
        exit 1
    fi
}
 
get_latest_revision()
{
    local repo="$1"
    svn log "$repo" | sed -n "2p" | cut -f 1 -d " " | sed "s/^r//"
}
 
ignore_generated_files()
{
    log "setting ignored files from subversion (this can take a while)"
    git svn show-ignore >> $GIT_EXCLUDE
    cat <<EOF >> $GIT_EXCLUDE
 
# Git files
.gitignore
EOF
}
 
clone_repository()
{
    local svn_repo="$1"
    local local_repo="$2"
    
    [ -z "$REVISION" ] && log "finding latest revision of $svn_repo"
    local revision=${REVISION:-$(get_latest_revision "$svn_repo")}
    
    log "creating git repository in $(pwd)/$local_repo"
    local empty_dirs=$(git svn clone -r $revision $svn_repo $local_repo 2>&1 | \
        grep "W: +empty_dir:" | cut -f 3 -d " ")
    local dir
    for dir in $empty_dirs; do
log "making empty directory: $dir"
        mkdir -p "$local_repo/$dir"
    done
pushd "$local_repo" >/dev/null
    ignore_generated_files
    popd >/dev/null
}
 
clone_external_plugins()
{
    log "checking for plugins installed with svn:externals"
 
    local plugins=$(svn propget svn:externals "$SVN_REPO/vendor/plugins")
    [ -z "$plugins" ] && return
 
pushd "$LOCAL_REPO" >/dev/null
    local plugin_dir="../plugins"
    mkdir -p "$plugin_dir"
    
    local line plugin svn_repo
    export IFS=$'\n' # iterate over lines, not words
for line in $plugins; do
plugin=$(echo $line | cut -f 1 -d " ")
if [ ! -e "$plugin_dir/$plugin" ]; then
svn_repo=$(echo $line | cut -f 2 -d " ")
clone_repository "$svn_repo" "$plugin_dir/$plugin"
fi
 
log "symlinking $plugin into $LOCAL_REPO/vendor/plugins"
pushd vendor/plugins >/dev/null
ln -sf "../../$plugin_dir/$plugin"
popd >/dev/null
echo "/vendor/plugins/$plugin" >> "$GIT_EXCLUDE"
done
unset IFS
popd >/dev/null
}
 
create_working_branch()
{
local local_repo="$1"
log "creating '$BRANCH' branch on $(pwd)/$local_repo"
pushd "$local_repo" >/dev/null
git checkout -b "$BRANCH"
popd >/dev/null
}
 
## Main program
 
[ -n "$DEBUG" ] && set -x
 
SVN_REPO="$1"
LOCAL_REPO="$2"
[ -z "$SVN_REPO" -o -z "$LOCAL_REPO" ] && usage
GIT_EXCLUDE="$(pwd)/$LOCAL_REPO/.git/info/exclude"
 
check_for_local_dir "$LOCAL_REPO"
clone_repository "$SVN_REPO" "$LOCAL_REPO"
if [ -e "$LOCAL_REPO/vendor/plugins" ]; then
clone_external_plugins
fi
create_working_branch "$LOCAL_REPO"