-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-updates
executable file
·94 lines (86 loc) · 2.17 KB
/
git-updates
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/git-updates
#
CWD=$(pwd)
PROG="${0##*/}"
trap cleanup SIGINT SIGTERM SIGKILL SIGQUIT SIGABRT SIGSTOP SIGSEGV
cleanup() {
echo -e "\n\n"
exit 0
}
usage() {
echo "Usage:"
echo "${PROG} [-c] [-h] [-d N]"
echo ""
echo " by default, recursively scans for git/git-svn repos and pulls updates"
echo ""
echo " -c 'check' - will only show repos that have pending changes"
echo " -dN 'depth' - will change the default scanning depth from 3 to N"
echo " -h 'help' - this usage text"
cleanup
}
while getopts ':chd:' opt; do
case $opt in
c) CHECK=1
;;
h) usage
;;
d) DEPTH="${OPTARG//[^0-9]/}"
;;
*) echo "Invalid option: -$OPTARG"
usage
;;
esac
done
for DIR in $(find . -maxdepth ${DEPTH:-3} -type d -iname .git -o -iname .hg )
do
# echo ./proxyapp/.git | cut -f 2 -d/
SUBDIR=${DIR:2}
if [ -z "${SUBDIR##*.git*}" ]
then
SUBDIR=${SUBDIR//\/.git}
if [ -d "${SUBDIR}/.git/svn/refs" ];
then
echo -n "checking git-svn repo ${SUBDIR}: "
cd ${SUBDIR}
if [ ${CHECK:-0} -eq 1 ]
then
git diff --quiet
test $? -eq 1 && echo "git-svn repo ${SUBDIR} has pending changes"
else
git svn fetch
fi
elif [ -e "${SUBDIR}/.git/config" -a -n "$(grep -w url ${SUBDIR}/.git/config)" ]
then
cd ${SUBDIR}
if [ ${CHECK:-0} -eq 1 ]
then
git diff --quiet
test $? -eq 1 && echo "git repo ${SUBDIR} has pending changes"
else
echo -n "checking git repo ${SUBDIR}: "
git pull --recurse 2>/dev/null || git pull --recurse-submodules
fi
fi
cd ${CWD}
elif [ -z "${SUBDIR##*.hg*}" ]
then
SUBDIR=${SUBDIR//\/.hg}
if [ -e "${SUBDIR}/.hg/hgrc" -a -n "$(grep -w default ${SUBDIR}/.hg/hgrc)" ]
then
cd ${SUBDIR}
if [ ${CHECK:-0} -eq 1 ]
then
hg update --check >/dev/null 2>&1
test $? -eq 1 && echo "mercurial repo ${SUBDIR} has pending changes"
else
echo -n "checking mercurial repo ${SUBDIR}: "
hg update
fi
cd ${CWD}
fi
fi
done