bib2html.py: Add incollection bibtype
[shutils.git] / git / git-pull-all
1 #!/bin/sh
2
3 # A script to recursively pull git repositories behind origin.
4
5 # Copyright (c) 2022 Stefan Huber
6 #
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
14 # conditions:
15 #
16 # The above copyright notice and this permission notice shall be
17 # included in all copies or substantial portions of the Software.
18 #
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.
27
28 set -e
29 set -u
30
31 showHelp()
32 {
33 echo "Recursively pull git repositories behind origin."
34 echo ""
35 echo "Usage:"
36 echo " git-pull-all [OPTIONS]"
37 echo " git-pull-all [OPTIONS] DIR"
38 echo ""
39 echo "OPTIONS:"
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"
43 echo ""
44 echo ""
45 echo "Examples:"
46 echo ""
47 echo "Recursively find git repositories and invoke pull if"
48 echo "branch is behind origin:"
49 echo ""
50 echo " git-pull-all"
51 echo ""
52 echo "Find git repositories in home directory and print"
53 echo "whether they are up to date:"
54 echo ""
55 echo " git-pull-all -n ~"
56
57 }
58
59 if ! options=$(getopt -u -o ahn -l ask,help,dry-run -- "$@"); then
60 showHelp >&2
61 exit 1
62 fi
63 set -- $options
64
65 optDryRun=0
66 optAsk=0
67
68 #Parse the arguments
69 while [ $# -gt 0 ]; do
70 case "$1" in
71 -h|--help) showHelp; exit 0 ;;
72 -n|--dry-run) optDryRun=1 ;;
73 -a|--ask) optAsk=1 ;;
74 --) shift; break ;;
75 -*) echo "Unrecognized option $1" >&2; showHelp >&2; exit 1 ;;
76 *) break ;;
77 esac
78 shift
79 done
80
81 for REPODIR in $(find "$@" -name .git -type d 2> /dev/null); do
82
83 REPO=$(dirname ${REPODIR})
84 echo "Run ${REPO} …"
85
86 if [ "${optAsk}" = 1 ]; then
87 read -p " Process [y/N]? " -n1 response
88 echo ""
89
90 [ "${response}" = "y" ] || continue
91 fi
92
93 git -C ${REPO} remote update
94
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"
97 else
98 if [ "${optDryRun}" = 1 ]; then
99 /usr/bin/echo -e "\e[1;31m Skipping due to dry-run\e[0m"
100 continue
101 fi
102 git -C ${REPO} pull
103 fi
104
105 done