3 # A script to recursively pull git repositories behind origin.
5 # Copyright (c) 2022 Stefan Huber
7 # Permission is hereby granted, free of charge, to any person
8 # obtaining a copy of this software and associated documentation
9 # files (the "Software"), to deal in the Software without
10 # restriction, including without limitation the rights to use,
11 # copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the
13 # Software is furnished to do so, subject to the following
16 # The above copyright notice and this permission notice shall be
17 # included in all copies or substantial portions of the Software.
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 # OTHER DEALINGS IN THE SOFTWARE.
33 echo "Usage: $0 [-h|--help]"
37 echo " -a, --ask ask user for each repo"
38 echo " -h, --help show this message"
39 echo " -n, --dry-run do not actually perform pull"
42 if ! options
=$
(getopt
-u -o ahn
-l ask
,help,dry-run
-- "$@"); then
52 while [ $# -gt 0 ]; do
54 -h|
--help) showHelp
; exit 0 ;;
55 -n|
--dry-run) optDryRun
=1 ;;
58 -*) echo "Unrecognized option $1" >&2; showHelp
>&2; exit 1 ;;
64 for REPODIR
in $
(find "$@" -name .git
-type d
2> /dev
/null
); do
66 REPO
=$
(dirname ${REPODIR})
69 if [ "${optAsk}" = 1 ]; then
70 read -p " Process [y/N]? " -n1 response
73 [ "${response}" = "y" ] ||
continue
76 git
-C ${REPO} remote update
78 if [ -z "$(git -C ${REPO} status -uno | grep 'Your branch is behind')" ] ; then
79 echo -e "\e[1;32m Already up to date\e[0m"
81 [ "${optDryRun}" = 1 ] && continue