autocorrect: non-breaking space before % in French fdo#41015
[LibreOffice.git] / g
blobe5a91f38cd5341d80b12b774a2c27675c71cda9a
1 #!/usr/bin/env bash
3 # Wrapper for git to handle more subdirs at the same time
6 # no params, no action
7 if [ "$#" -eq "0" ] ; then
8 git
9 echo
10 echo "Additional options available only in this 'g' wrapper:"
11 echo
12 echo "Usage: g [options] [git commands]"
13 echo " -f Force - act on all the repos, not only the changed ones"
14 echo " -s Silent - do not report the repo names."
15 echo " -1 report the repos name on the first line of the output as <repo>:"
16 echo " -z just to some house cleaning (hooks mostly). this is a stand-alone option as in ./g -z"
17 echo " --set-push-user [username] re-write an existing tree's config with an fd.o commit account name"
18 exit $?
21 if [ ! "`type -p git`" ]; then
22 echo "Cannot find the git binary! Is git installed and is in PATH?"
23 exit 1
26 pushd $(dirname $0) > /dev/null
27 COREDIR=$(pwd)
28 popd > /dev/null
30 refresh_hooks()
32 repo=$1
33 case "$repo" in
34 core)
35 pushd $COREDIR > /dev/null
36 for hook_name in $(ls -1 $COREDIR/git-hooks) ; do
37 hook=".git/hooks/$hook_name"
38 if [ ! -x "$hook" -a ! -L "$hook" ] ; then
39 rm -f "$hook"
40 ln -s "git-hooks/$hook_name" "$hook"
42 done
43 popd > /dev/null
45 translations)
46 if [ -d $COREDIR/clone/translations ] ; then
47 pushd $COREDIR/clone/translations > /dev/null
48 for hook_name in $(ls -1 $COREDIR/clone/translations/git-hooks) ; do
49 hook=".git/hooks/$hook_name"
50 rm -f "$hook"
51 ln -sf "git-hooks/$hook_name" "$hook"
52 done
53 # .gitattribute should be per-repo, avoid entangling repos
54 if [ -L .gitattributes ] ; then
55 rm -f .gitattributes
57 popd > /dev/null
60 help|dictionaries)
61 if [ -d $COREDIR/clone/$repo ] ; then
62 pushd $COREDIR/clone/$repo > /dev/null
63 # fixme: we should really keep these per-repo to
64 # keep the repos independant. since these two
65 # are realy not independant yet, we keep using core's hooks
66 for hook_name in $(ls -1 $COREDIR/git-hooks) ; do
67 hook=".git/hooks/$hook_name"
68 rm -f "$hook"
69 ln -sf "$COREDIR/git-hooks/$hook_name" "$hook"
70 done
71 # .gitattribute should be per-repo, avoid entangling repos
72 if [ -L .gitattributes ] ; then
73 rm -f .gitattributes
75 popd > /dev/null
78 esac
81 refresh_all_hooks()
83 repos="core $(cat "$COREDIR/bin/repo-list")"
84 for repo in $repos ; do
85 refresh_hooks $repo
86 done
89 postprocess()
91 rc=$1
92 if $DO_HOOK_REFRESH ; then
93 refresh_all_hooks
96 exit $rc;
99 CLONEDIR="$COREDIR/clone"
100 if [ ! -e ${CLONEDIR} ]; then mkdir -p "$CLONEDIR"; fi
102 # extra params for some commands, like log
103 EXTRA=
104 COMMAND="$1"
105 PAGER=
106 RELATIVIZE=1
107 PUSH_ALL=
108 ALLOW_EMPTY=
109 KEEP_GOING=0
110 REPORT_REPOS=1
111 REPORT_COMPACT=0
112 DO_HOOK_REFRESH=false
114 while [ "${COMMAND:0:1}" = "-" ] ; do
115 case "$COMMAND" in
116 -f) KEEP_GOING=1
118 -s) REPORT_REPOS=0
120 -1) REPORT_COMPACT=1
122 --set-push-user)
123 shift
124 PUSH_USER="$1"
127 DO_HOOK_REFRESH=true
128 postprocess 0
130 esac
131 shift
132 COMMAND="$1"
133 done
135 case "$COMMAND" in
136 apply)
137 EXTRA="-p0 --stat --apply --index --ignore-space-change --whitespace=error"
138 RELATIVIZE=0
140 clone|fetch|pull)
141 DO_HOOK_REFRESH=true
143 diff)
144 PAGER='--no-pager'
145 REPORT_REPOS=0
147 log)
148 if [ "$#" = "1" ] ; then
149 EXTRA='-1'
151 PAGER='--no-pager'
153 push)
154 if [ "$#" != "1" ] ; then
155 PUSH_ALL=1
158 esac
160 # absolutize the parameters first
161 unset FILES
162 FILESNUM=0
163 while shift ; do
164 PARAM="$1"
165 if [ -z "$PARAM" ] ; then
166 continue
167 elif [ "${PARAM:0:1}" = "-" ] ; then
168 if [ \( "$COMMAND" = "checkout" -a "$PARAM" = "-b" \) -o \
169 \( "$COMMAND" = "clone" -a "$PARAM" = "--reference" \) -o \
170 \( "$COMMAND" = "commit" -a "$PARAM" = "-m" \) -o \
171 \( "$COMMAND" = "commit" -a "$PARAM" = "-am" \) -o \
172 \( "$COMMAND" = "tag" -a "$PARAM" = "-m" \) ]
173 then
174 # params that take an argument
175 FILES[$FILESNUM]="$PARAM"
176 FILESNUM=$(($FILESNUM+1))
177 shift
178 FILES[$FILESNUM]="$1"
179 FILESNUM=$(($FILESNUM+1))
180 else
181 if [ "$COMMAND" = "commit" -a "$PARAM" = "-F" ]
182 then
183 shift
184 # this still needs some magic to handle relative paths
185 EXTRA="${EXTRA} -F ${1}"
186 else
187 [ "$COMMAND" = "commit" -a "$PARAM" = "--allow-empty" ] && ALLOW_EMPTY=1
188 FILES[$FILESNUM]="$PARAM"
189 FILESNUM=$(($FILESNUM+1))
192 else
193 if [ "$COMMAND" = "apply" ] ; then
194 grep -qs $'^+ *\t' "$PARAM" && {
195 echo "Patch '$PARAM' introduces tabs in indentation, aborting."
196 echo
197 echo "Please fix the patch (something like s/^\(+ *\)\t/\1 /) and try again."
198 echo
199 exit 1
203 # make the paths absolute
204 FILES[$FILESNUM]=$(perl -e 'use Cwd "abs_path"; print abs_path(shift);' "$PARAM")
205 if [ -z "${FILES[$FILESNUM]}" -o ! -e "${FILES[$FILESNUM]}" ] ; then
206 # it is probably not a file, but a tag name, or something
207 FILES[$FILESNUM]="$PARAM"
209 FILESNUM=$(($FILESNUM+1))
211 done
213 # do it!
214 DIRS="core $(cd $CLONEDIR ; ls)"
215 if [ "$COMMAND" = "clone" ] ; then
216 DIRS=$(cat "$COREDIR/bin/repo-list")
218 for REPO in $DIRS ; do
219 DIR="$CLONEDIR/$REPO"
220 NAME="$REPO"
221 if [ "$REPO" = "core" ] ; then
222 DIR="$COREDIR"
223 NAME="main repo"
226 if [ -d "$DIR" -a "z$PUSH_USER" != "z" ]; then
227 echo "setting up push url for $DIR"
228 (cd $DIR && git config remote.origin.pushurl "ssh://${PUSH_USER}@git.freedesktop.org/git/libreoffice/${REPO}")
229 elif [ \( -d "$DIR" -a -d "$DIR"/.git \) -o \( "$COMMAND" = "clone" \) ] ; then
231 # executed in a subshell
232 if [ "$COMMAND" != "clone" ] ; then
233 cd "$DIR"
234 else
235 cd "$CLONEDIR"
238 # relativize the absolutized params again if we want to operate
239 # only on the files belonging to this exact repo
240 if [ "$RELATIVIZE" = "1" -a -n "$FILES" ] ; then
241 FILESNUM=0
242 INSERTNUM=0
243 PWD=$(pwd)
244 PWDLEN=$(pwd | wc -c)
245 for I in "${FILES[@]}" ; do
246 I="${I//@REPO@/${REPO}}"
247 unset FILES[$FILESNUM]
248 FILESNUM=$(($FILESNUM+1))
249 # filter out files that don't belong to this repo
250 if [ \( "${I:0:1}" = "/" \) -a \( "$COMMAND" != "clone" \) ] ; then
251 if [ "${I:0:$PWDLEN}" = "$PWD/" ] ; then
252 FILES[$INSERTNUM]="${I:$PWDLEN}"
253 INSERTNUM=$(($INSERTNUM+1))
255 else
256 FILES[$INSERTNUM]="$I"
257 INSERTNUM=$(($INSERTNUM+1))
259 done
260 [ "$INSERTNUM" = "0" ] && exit 0
263 # some extra params
264 case "$COMMAND" in
265 apply)
266 for I in * ; do
267 if [ -d "$I" ] ; then
268 EXTRA="$EXTRA --include=$I/*"
269 else
270 EXTRA="$EXTRA --include=$I"
272 done
274 commit)
275 if [ "$ALLOW_EMPTY" != "1" ] ; then
276 [ -z "$(git diff-index --name-only HEAD --)" ] && exit 0
279 push)
280 if [ "$PUSH_ALL" != "1" ] ; then
281 [ -n "$(git rev-list origin..HEAD)" ] || exit 0
284 status)
285 LOCALCOMMITS="$(git rev-list origin..HEAD)"
286 if [ -z "$LOCALCOMMITS" ] ; then
287 [ -z "$(git diff-index --name-only HEAD --)" ] && exit 0
290 clone)
291 EXTRA="$(git config remote.origin.url)"
292 EXTRA=${EXTRA/core/${REPO}}
294 esac
296 # do it!
297 if [ "$COMMAND" != "clone" -o ! -d $DIR ] ; then
298 if [ "$REPORT_REPOS" = "1" -a "$COMMAND" != "grep" ] ; then
299 if [ "$REPORT_COMPACT" = "1" ] ; then
300 echo -n "${REPO}:"
301 else
302 echo "===== $NAME ====="
305 git $PAGER "$COMMAND" $EXTRA "${FILES[@]}"
306 RETURN=$?
309 # now we can change the dir in case of clone as well
310 if [ "$COMMAND" = "clone" ] ; then
311 cd $DIR
314 case "$COMMAND" in
315 pull|clone)
316 # update links
317 if [ "$DIR" != "$COREDIR" ]; then
318 for link in $(ls) ; do
319 if [ ! -e "$COREDIR/$link" ] ; then
320 if test -h "$COREDIR/$link"; then
321 rm "$COREDIR/$link"
322 echo -n "re-"
324 echo "creating missing link $link"
325 ln -s "$DIR/$link" "$COREDIR/$link"
327 done
330 status)
331 # git status returns error in some versions, clear that
332 RETURN=0
334 grep)
335 # git grep return an 'error' if nothing is found
336 # still we should continue grepping the other repos
337 RETURN=0
339 esac
340 if [ "$KEEP_GOING" = "1" ] ; then
341 RETURN=0
344 exit $RETURN
345 ) || postprocess $?
347 done
349 # Cleanup the broken links
350 if [ "$COMMAND" = "pull" ] ; then
351 for link in $(ls $COREDIR) ; do
352 if [ -h "$COREDIR/$link" -a ! -e "$COREDIR/$link" ]; then
353 echo "Removing broken link $link"
354 rm $COREDIR/$link
356 done
359 # warn
360 if [ "$COMMAND" = "apply" ] ; then
361 echo
362 echo "Don't forget to check the status & commit now ;-)"
363 echo
366 postprocess $?
368 # vi:set shiftwidth=4 expandtab: