forked from oldratlee/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswtrunk
executable file
·47 lines (41 loc) · 1.19 KB
/
swtrunk
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
#!/bin/bash
# @Function
# switch svn work directory to trunk.
#
# @Usage
# $ ./swtrunk [<svn work dir>...]
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/vcs.md#-swtrunk
# @author Jerry Lee (oldratlee at gmail dot com)
# NOTE: $'foo' is the escape sequence syntax of bash
readonly ec=$'\033' # escape char
readonly eend=$'\033[0m' # escape end
colorEcho() {
local color=$1
shift
# if stdout is console, turn on color output.
[ -t 1 ] && echo "${ec}[1;${color}m$*$eend" || echo "$@"
}
redEcho() {
colorEcho 31 "$@"
}
greenEcho() {
colorEcho 32 "$@"
}
[ $# -eq 0 ] && dirs=(.) || dirs=("$@")
for d in "${dirs[@]}"; do
[ ! -d "${d}/.svn" ] && {
redEcho "directory $d is not a svn work directory, ignore directory $d !"
continue
}
(
cd "$d" &&
branches=$(svn info | grep '^URL' | awk '{print $2}') &&
trunk=$(echo "$branches" | awk -F'/branches/' '{print $1}')/trunk &&
if svn sw "$trunk"; then
greenEcho "svn work directory $d switch from ${branches} to ${trunk} ."
else
redEcho "fail to switch $d to trunk!"
fi
)
done