-
Notifications
You must be signed in to change notification settings - Fork 0
/
svn-git.sh
106 lines (93 loc) · 2.09 KB
/
svn-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
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
#!/bin/sh
# by Mike McQuaid (https://github.com/mikemcquaid/scripts)
SVN_ALIAS=$(alias svn 2>/dev/null|sed -e 's/alias svn=//')
svn_root() {
[ -d .svn ] || (echo "No .svn directory found" && return)
OLDPWD=$PWD
while [ -d ../.svn ]
do
cd ..
done
SVN_INFO_URL=$(svn info 2>/dev/null | grep URL:) || return
SVN_URL=$(echo $SVN_INFO | sed -e 's/URL: //')
SVN_BRANCH=$(echo $SVN_INFO | grep -oe '\(trunk\|branches/[^/]\+\|tags/[^/]\+\)')
[ -n "$SVN_BRANCH" ] || return
SVN_ROOT=${SVN_URL%$SVN_BRANCH}
echo "$SVN_ROOT"
cd $OLDPWD
}
# Makes changing branches in Subversion more like Git
svn_git_checkout() {
if echo "$@" | grep "://"
then
svn "$@"
return
fi
NEW_BRANCH="$1"
[ -n "$NEW_BRANCH" ] || (echo "No branch specified" && return)
[ -d .svn ] || (echo "No .svn directory found" && return)
SVN_ROOT=$(svn_root)
if [ $NEW_BRANCH != "trunk" ]
then
echo "Searching branches for $NEW_BRANCH"
for BRANCH in $(svn ls ${SVN_ROOT}/branches)
do
[ "$NEW_BRANCH/" != $BRANCH ] && continue
FOUND_BRANCH="branches/$BRANCH"
break
done
if [ -z "$FOUND_BRANCH" ]
then
echo "Searching tags for $NEW_BRANCH"
for TAG in $(svn ls ${SVN_ROOT}/tags)
do
[ "$NEW_BRANCH/" != $TAG ] && continue
FOUND_BRANCH="tags/$TAG"
break
done
fi
if [ -z "$FOUND_BRANCH" ]
then
echo "Could not find a branch or tag named $NEW_BRANCH"
cd $OLDPWD
return
else
NEW_BRANCH="$FOUND_BRANCH"
fi
fi
OLDPWD=$PWD
while [ -d ../.svn ]
do
cd ..
done
echo svn switch "$SVN_ROOT$NEW_BRANCH"
svn switch "$SVN_ROOT$NEW_BRANCH"
cd $OLDPWD
}
case "$1" in
co)
svn_git_checkout "$@"
;;
checkout)
svn_git_checkout "$@"
;;
log)
svn "$@"|less -FX
;;
branch)
SVN_ROOT=$(svn_root)
echo "Branches:"
svn ls ${SVN_ROOT}/branches
echo
echo "Tags:"
svn ls ${SVN_ROOT}/tags
;;
diff)
[ -n "$DIFF" ] && DIFF_ARG="--diff-cmd=$DIFF"
svn $DIFF_ARG "$@"|less -FXR
;;
*)
svn "$@"
;;
esac
alias svn=$SVN_ALIAS