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 "Recursively pull git repositories behind origin."
36 echo " git-pull-all [OPTIONS]"
37 echo " git-pull-all [OPTIONS] DIR"
40 echo " -a, --ask ask user for each repo before pull"
41 echo " -h, --help show this message"
42 echo " -n, --dry-run do not actually perform pull"
47 echo "Recursively find git repositories and invoke pull if"
48 echo "branch is behind origin:"
52 echo "Find git repositories in home directory and print"
53 echo "whether they are up to date:"
55 echo " git-pull-all -n ~"
59 if ! options
=$
(getopt
-u -o ahn
-l ask
,help,dry-run
-- "$@"); then
69 while [ $# -gt 0 ]; do
71 -h|
--help) showHelp
; exit 0 ;;
72 -n|
--dry-run) optDryRun
=1 ;;
75 -*) echo "Unrecognized option $1" >&2; showHelp
>&2; exit 1 ;;
81 for REPODIR
in $
(find "$@" -name .git
-type d
2> /dev
/null
); do
83 REPO
=$
(dirname ${REPODIR})
86 if [ "${optAsk}" = 1 ]; then
87 read -p " Process [y/N]? " -n1 response
90 [ "${response}" = "y" ] ||
continue
93 git
-C ${REPO} remote update
95 if [ -z "$(git -C ${REPO} status -uno | grep 'Your branch is behind')" ] ; then
96 /usr
/bin
/echo -e "\e[1;32m Already up to date\e[0m"
98 if [ "${optDryRun}" = 1 ]; then
99 /usr
/bin
/echo -e "\e[1;31m Skipping due to dry-run\e[0m"