Skip to content

Commit 03996a4

Browse files
committed
improve swtrunk
1 parent eac7403 commit 03996a4

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

swtrunk.sh

+34-11
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,41 @@
77
#
88
# @author Jerry Lee
99

10+
colorEcho() {
11+
local color=$1
12+
shift
13+
if [ -c /dev/stdout ] ; then
14+
# if stdout is console, turn on color output.
15+
echo -ne "\033[1;${color}m"
16+
echo -n "$@"
17+
echo -e "\033[0m"
18+
else
19+
echo "$@"
20+
fi
21+
}
22+
23+
redEcho() {
24+
colorEcho 31 "$@"
25+
}
26+
27+
greenEcho() {
28+
colorEcho 32 "$@"
29+
}
30+
1031
[ $# -eq 0 ] && dirs=(.) || dirs=("$@")
1132

1233
for d in "${dirs[@]}" ; do
13-
[ ! -d ${d}/.svn ] && {
14-
echo "$d is not svn work dir!"
15-
continue
16-
}
17-
(
18-
cd "$d"
19-
branches=`svn info | grep '^URL' | awk '{print $2}'`
20-
trunk=`echo $branches | awk -F'/branches/' '{print $1}'`/trunk
21-
svn sw "$trunk"
22-
echo "svn work dir $d switch from ${branches} to ${trunk} ."
23-
)
34+
[ ! -d ${d}/.svn ] && {
35+
redEcho "directory $d is not a svn work directory, ignore directory $d !"
36+
continue
37+
}
38+
(
39+
cd "$d" &&
40+
branches=`svn info | grep '^URL' | awk '{print $2}'` &&
41+
trunk=`echo $branches | awk -F'/branches/' '{print $1}'`/trunk &&
42+
43+
svn sw "$trunk" &&
44+
greenEcho "svn work directory $d switch from ${branches} to ${trunk} ." ||
45+
redEcho "fail to switch $d to trunk!"
46+
)
2447
done

0 commit comments

Comments
 (0)