3 # Wrapper for git to handle more subdirs at the same time
7 if [ "$#" -eq "0" ] ; then
10 echo "Additional options available only in this 'g' wrapper:"
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"
21 if [ ! "`type -p git`" ]; then
22 echo "Cannot find the git binary! Is git installed and is in PATH?"
26 pushd $
(dirname $0) > /dev
/null
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
40 ln -s "git-hooks/$hook_name" "$hook"
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"
51 ln -sf "git-hooks/$hook_name" "$hook"
53 # .gitattribute should be per-repo, avoid entangling repos
54 if [ -L .gitattributes
] ; then
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"
69 ln -sf "$COREDIR/git-hooks/$hook_name" "$hook"
71 # .gitattribute should be per-repo, avoid entangling repos
72 if [ -L .gitattributes
] ; then
83 repos
="core $(cat "$COREDIR/bin
/repo-list
")"
84 for repo
in $repos ; do
92 if $DO_HOOK_REFRESH ; then
99 CLONEDIR
="$COREDIR/clone"
100 if [ ! -e ${CLONEDIR} ]; then mkdir
-p "$CLONEDIR"; fi
102 # extra params for some commands, like log
112 DO_HOOK_REFRESH
=false
114 while [ "${COMMAND:0:1}" = "-" ] ; do
137 EXTRA
="-p0 --stat --apply --index --ignore-space-change --whitespace=error"
148 if [ "$#" = "1" ] ; then
154 if [ "$#" != "1" ] ; then
160 # absolutize the parameters first
165 if [ -z "$PARAM" ] ; then
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" \
) ]
174 # params that take an argument
175 FILES
[$FILESNUM]="$PARAM"
176 FILESNUM
=$
(($FILESNUM+1))
178 FILES
[$FILESNUM]="$1"
179 FILESNUM
=$
(($FILESNUM+1))
181 if [ "$COMMAND" = "commit" -a "$PARAM" = "-F" ]
184 # this still needs some magic to handle relative paths
185 EXTRA
="${EXTRA} -F ${1}"
187 [ "$COMMAND" = "commit" -a "$PARAM" = "--allow-empty" ] && ALLOW_EMPTY
=1
188 FILES
[$FILESNUM]="$PARAM"
189 FILESNUM
=$
(($FILESNUM+1))
193 if [ "$COMMAND" = "apply" ] ; then
194 grep -qs $
'^+ *\t' "$PARAM" && {
195 echo "Patch '$PARAM' introduces tabs in indentation, aborting."
197 echo "Please fix the patch (something like s/^\(+ *\)\t/\1 /) and try again."
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))
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"
221 if [ "$REPO" = "core" ] ; then
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
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
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))
256 FILES
[$INSERTNUM]="$I"
257 INSERTNUM
=$
(($INSERTNUM+1))
260 [ "$INSERTNUM" = "0" ] && exit 0
267 if [ -d "$I" ] ; then
268 EXTRA
="$EXTRA --include=$I/*"
270 EXTRA
="$EXTRA --include=$I"
275 if [ "$ALLOW_EMPTY" != "1" ] ; then
276 [ -z "$(git diff-index --name-only HEAD --)" ] && exit 0
280 if [ "$PUSH_ALL" != "1" ] ; then
281 [ -n "$(git rev-list origin..HEAD)" ] ||
exit 0
285 LOCALCOMMITS
="$(git rev-list origin..HEAD)"
286 if [ -z "$LOCALCOMMITS" ] ; then
287 [ -z "$(git diff-index --name-only HEAD --)" ] && exit 0
291 EXTRA
="$(git config remote.origin.url)"
292 EXTRA
=${EXTRA/core/${REPO}}
297 if [ "$COMMAND" != "clone" -o ! -d $DIR ] ; then
298 if [ "$REPORT_REPOS" = "1" -a "$COMMAND" != "grep" ] ; then
299 if [ "$REPORT_COMPACT" = "1" ] ; then
302 echo "===== $NAME ====="
305 git
$PAGER "$COMMAND" $EXTRA "${FILES[@]}"
309 # now we can change the dir in case of clone as well
310 if [ "$COMMAND" = "clone" ] ; then
317 if [ "$DIR" != "$COREDIR" ]; then
318 for link
in $
(ls) ; do
319 if [ ! -e "$COREDIR/$link" ] ; then
320 if test -h "$COREDIR/$link"; then
324 echo "creating missing link $link"
325 ln -s "$DIR/$link" "$COREDIR/$link"
331 # git status returns error in some versions, clear that
335 # git grep return an 'error' if nothing is found
336 # still we should continue grepping the other repos
340 if [ "$KEEP_GOING" = "1" ] ; then
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"
360 if [ "$COMMAND" = "apply" ] ; then
362 echo "Don't forget to check the status & commit now ;-)"
368 # vi:set shiftwidth=4 expandtab: