-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.rc
43 lines (41 loc) · 1.21 KB
/
git.rc
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
#!/bin/bash
update_repo(){
prev_dir="`pwd`"
if [ "@$1" = "@" ]; then
echo "Error: update_repo requires a path then a URL but the 1st param is missing."
exit 1
fi
# if [ "@$2" = "@" ]; then
# echo "Error: update_repo requires a path then a URL but the 2nd param is missing."
# fi
path=$1
url=$2
options=$3
if [ -d "$path" ]; then
cd "$path"
if [ $? -ne 0 ]; then
echo "Error: 'cd \"$path\"' failed in \"`pwd`\"."
cd "$prev_dir"
return 1
fi
git pull $options --no-rebase
if [ $? -ne 0 ]; then
echo "Error: 'git pull' failed in \"`pwd`\"."
cd "$prev_dir"
return 2
fi
else
if [ "@$2" = "@" ]; then
echo "Error: update_repo requires a path then a URL when there is no existing repo directory from which to pull but the 2nd param is missing."
cd "$prev_dir"
return 1
fi
git clone $options "$url" "$path"
if [ $? -ne 0 ]; then
echo "Error: 'git clone \"$url\" \"$path\"' failed in \"`pwd`\"."
cd "$prev_dir"
return 2
fi
fi
cd "$prev_dir"
}