-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgit_pull.sh
59 lines (52 loc) · 1.1 KB
/
git_pull.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
#!/bin/sh
#
# author: yanue
# time: 2015-11-28
# git pull tool
# when project has untracked and local change files
#
# usage:
# gpl [project path]
#
# update:
# -- echo delete files
#
# author: yanue
# email: [email protected]
# time: 2015-11-28
# update: 2016-01-07
tmp_file='/tmp/git_pull_tmp';
git='/usr/local/bin/git';
if [ $# -gt 0 ] ;then
cd $1;
if [ $? != 0 ]; then
echo $1 ': path not found';
exit 0;
fi
else
cd ${PWD};
fi
if [ ! -d ".git" ]; then
echo 'this is not a git project path';
exit 0;
fi
pwd;
# git pull once
$git pull 2> $tmp_file;
# if has errors
if [ $? != 0 ]; then
# delete untracked and local change files
## all those files each have an epmty space char
echo 'need delete files:';
cat $tmp_file | sed -n '/^\s/p' | awk '{print " "$1}'
cat $tmp_file | sed -n '/^\s/p' | awk '{print $1}' | xargs rm -f
# pull again
$git pull;
# set tmp file to empty
cat /dev/null > $tmp_file;
fi
# addon options
chmod -R 777 .
chown -R www.www .
# end
echo 'done'