-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-git-to-sae.sh
executable file
·64 lines (48 loc) · 1.57 KB
/
sync-git-to-sae.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
#!/bin/sh
##################################################
# Brief Sync your git commitment to SAE.
# Author LiJunjie, [email protected]
# Usage sync-git-to-sae.sh <username> [src dir]
# Version 0.01
# Date 11-06-16 16:09:25
# modiy papersnake,[email protected]
##################################################
# username of SAE
username="$1"
# src_dir is the root directory of all things which
# you want to deploy to SAE svn repository.
if [ -z "$2" ]; then
src_dir="."
else
src_dir="$2"
fi
svn_dir=/var/tmp/svn_dir
# remove the deleted items from svn repository
svn_rm_deleted() {
deleted_items=`svn status | grep ^! | awk '{ print $2}'`
if ! [ -z "$deleted_items" ]; then
svn rm "$deleted_items"
fi
}
# add new items from svn repository
svn_add_new() {
#new_items=`svn status | grep ^? | awk '{ print $2}'`
#if ! [ -z "$new_items" ]; then
# svn add "$new_items"
#fi
svn st | awk '{if ($1 == "?") { print $2}}' | xargs svn add
}
echo "Checkout svn repository from SAE"
# SVN_PASSWD variable come from travis encrypted environment variables
svn co https://svn.sinaapp.com/stmall/ "$svn_dir" --username "$username" --password "$SVN_PASSWD" --no-auth-cache || exit 1
echo "Sync from git repository"
cd $src_dir
git diff --relative --no-color HEAD^..HEAD >/var/tmp/diff.patch
cd $svn_dir/2
patch -p1 < /var/tmp/diff.patch
cd $svn_dir/2
svn_rm_deleted
svn_add_new
echo "Deploy to SAE"
svn ci -m "$TRAVIS_COMMIT" --username "$username" --password "$SVN_PASSWD" --no-auth-cache || exit 1
echo "Done"