tdf#139102 Erase with COL_TRANSPARENT doesn't do what it should
[LibreOffice.git] / g
blob8b733fc878c664e87867cbf9cf3f0bd02a8896fb
1 #!/usr/bin/env bash
3 # Wrapper for git to handle more subdirs at the same time
6 if [ -n "$g_debug" ] ; then
7 set -x
8 fi
10 SUBMODULES_ALL="dictionaries helpcontent2 translations"
12 pushd $(dirname $0) > /dev/null
13 if [ -f config_host.mk ] ; then
14 # we are in the BUILDDIR
15 SRC_ROOT=$(< config_host.mk grep -a SRC_ROOT | sed -e "s/.*=//")
16 else
17 SRC_ROOT=$(pwd)
19 popd > /dev/null
21 COREDIR="$SRC_ROOT"
23 usage()
25 git
26 echo
27 echo "Usage: g [options] [git (checkout|clone|fetch|grep|pull|push|reset) [git options/args..]]"
28 echo ""
29 echo " -z restore the git hooks and do other sanity checks"
32 refresh_submodule_hooks()
34 local repo=$1
35 local hook
36 local hook_name
38 if [ -d "${repo?}"/.git ] ; then
39 # use core's hook by default
40 for hook_name in "${COREDIR?}/.git-hooks"/* ; do
41 if [ ! -e "${hook_name}" ] ; then
42 continue
44 hook="${repo?}/.git/hooks/${hook_name##*/}"
45 if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then
46 rm -f "${hook?}"
47 ln -sf "${hook_name}" "${hook?}"
49 done
50 # override if need be by the submodules' own hooks
51 for hook_name in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
52 if [ ! -e "${hook_name}" ] ; then
53 continue
55 hook="${repo?}/.git/hooks/${hook_name##*/}"
56 if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then
57 rm -f "${hook?}"
58 ln -sf "${hook_name}" "${hook?}"
60 done
61 elif [ -d .git/modules/"${repo}"/hooks ] ; then
62 for hook_name in "${COREDIR?}/.git-hooks"/* ; do
63 if [ ! -e "${hook_name}" ] ; then
64 continue
66 hook=".git/modules/${repo?}/hooks/${hook_name##*/}"
67 if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then
68 rm -f "${hook?}"
69 ln -sf "${hook_name}" "${hook?}"
71 done
72 # override if need be by the submodules' own hooks
73 for hook_name in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
74 if [ ! -e "${hook_name}" ] ; then
75 continue
77 hook=".git/modules/${repo?}/hooks/${hook_name##*/}"
78 if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then
79 rm -f "${hook?}"
80 ln -sf "${hook_name}" "${hook?}"
82 done
87 refresh_all_hooks()
89 local repo
90 local hook_name
91 local hook
93 pushd "${COREDIR?}" > /dev/null
94 for hook_name in "${COREDIR?}/.git-hooks"/* ; do
95 hook=".git/hooks/${hook_name##*/}"
96 if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then
97 rm -f "${hook?}"
98 ln -sf "${hook_name}" "${hook?}"
100 done
102 for repo in ${SUBMODULES_ALL?} ; do
103 refresh_submodule_hooks "$repo"
104 done
105 popd > /dev/null
109 set_push_url()
111 local repo
113 repo="$1"
114 if [ -n "$repo" ] ; then
115 pushd "${COREDIR?}/${repo?}" > /dev/null
116 else
117 pushd "${COREDIR?}" > /dev/null
118 repo="core"
120 echo "setting up push url for ${repo?}"
121 if [ "${repo?}" = "helpcontent2" ] ; then
122 git config remote.origin.pushurl "ssh://${PUSH_USER}logerrit/help"
123 else
124 git config remote.origin.pushurl "ssh://${PUSH_USER}logerrit/${repo?}"
126 popd > /dev/null
129 set_push_urls()
131 PUSH_USER="$1"
132 set_push_url
133 for repo in ${SUBMODULES_ACTIVE?} ; do
134 set_push_url "${repo?}"
135 done
138 get_active_submodules()
140 SUBMODULES_ACTIVE=""
141 local repo
143 for repo in ${SUBMODULES_ALL?} ; do
144 if [ -d "${repo?}"/.git ] || [ -f "${repo?}"/.git ] ; then
145 SUBMODULES_ACTIVE="${repo?} ${SUBMODULES_ACTIVE?}"
147 done
150 get_configured_submodules()
152 SUBMODULES_CONFIGURED=""
153 if [ -f config_host.mk ] ; then
154 SUBMODULES_CONFIGURED=$(< config_host.mk grep -a GIT_NEEDED_SUBMODULES | sed -e "s/.*=//")
155 else
156 # if we need the configured submodule before the configuration is done. we assumed you want them all
157 SUBMODULES_CONFIGURED=${SUBMODULES_ALL?}
161 get_git_reference()
163 REFERENCED_GIT=""
164 if [ -f config_host.mk ]; then
165 REFERENCED_GIT=$(< config_host.mk grep -a GIT_REFERENCE_SRC | sed -e "s/.*=//")
167 LINKED_GIT=""
168 if [ -f config_host.mk ]; then
169 LINKED_GIT=$(< config_host.mk grep -a GIT_LINK_SRC | sed -e "s/.*=//")
173 do_shortcut_update()
175 local module
176 local repo
178 for module in $SUBMODULES_CONFIGURED ; do
179 if [ ! -d "${module?}"/.git ] ; then
180 case "${module?}" in
181 helpcontent2)
182 if [ -d clone/help/.git ] ; then
183 repo="clone/help/.git"
187 if [ -d clone/"${module?}"/.git ] ; then
188 repo="clone/${module?}/.git"
191 esac
192 if [ -n "$repo" ] ; then
193 cp -r "${repo?}" "${module?}/."
196 done
199 do_git_cmd()
201 echo "cmd:$*"
202 git "$@"
203 git submodule foreach git "$@" $KEEP_GOING
206 do_checkout()
208 local cmd
209 local create_branch="0"
210 local branch
211 local module
213 git checkout "$@" || return $?
214 for cmd in "$@" ; do
215 if [ "$cmd" = "-f" ]; then
216 continue
217 elif [ "$cmd" = "-b" ] ; then
218 create_branch=1
219 elif [ "$create_branch" = "1" ] ; then
220 branch="$cmd"
221 create_branch=0
223 done
224 if [ -f .gitmodules ] ; then
225 git submodule update --progress
226 if [ -n "$branch" ] ; then
227 git submodule foreach git checkout -b "${branch}" HEAD || return $?
229 else
230 # now that is the nasty case we moved prior to submodules
231 # delete the submodules left over if any
232 for module in $SUBMODULES_ALL ; do
233 echo "clean-up submodule $module"
234 rm -fr "${module}"
235 done
236 # make sure we have the needed repo in clone
237 ./g clone && ./g -f checkout "$@" || return $?
239 return $?
242 do_reset()
244 git reset "$@" || return $?
245 if [ -f .gitmodules ] ; then
246 git submodule update --progress || return $?
247 else
248 # now that is the nasty case we moved prior to submodules
249 # delete the submodules left over if any
250 for module in $SUBMODULES_ALL ; do
251 echo "clean-up submodule $module"
252 rm -fr "${module}"
253 done
254 # make sure we have the needed repo in clone
255 ./g clone && ./g -f reset "$@"
257 return $?;
260 do_init_modules()
262 local module
263 local configured
265 do_shortcut_update
267 for module in $SUBMODULES_CONFIGURED ; do
268 if [ -n "$LINKED_GIT" ] ; then
269 if ! [ -d ".git/modules/${module}" ]; then
270 ./bin/git-new-module-workdir "${LINKED_GIT}/${module}" "${module}"
273 configured=$(git config --local --get submodule."${module}".url)
274 if [ -z "$configured" ] ; then
275 git submodule init "$module" || return $?
277 done
278 for module in $SUBMODULES_CONFIGURED ; do
279 if [ -n "$REFERENCED_GIT" ] ; then
280 git submodule update --reference "$REFERENCED_GIT/.git/modules/$module" --progress "$module" || return $?
281 else
282 git submodule update --progress "$module" || return $?
284 done
285 return 0
289 # no params, no action
290 if [ "$#" -eq "0" ] ; then
291 usage
294 if [ ! "$(type -p git)" ]; then
295 echo "Cannot find the git binary! Is git installed and is in PATH?"
296 exit 1
300 get_active_submodules
301 get_configured_submodules
302 get_git_reference
307 # extra params for some commands, like log
308 EXTRA=
309 COMMAND="$1"
310 PAGER=
311 RELATIVIZE=1
312 PUSH_ALL=
313 PUSH_USER=
314 PUSH_NOTES=
315 LAST_WORKING=
316 SET_LAST_WORKING=
317 ALLOW_EMPTY=
318 KEEP_GOING=
319 REPORT_REPOS=1
320 REPORT_COMMANDS=0
321 REPORT_COMPACT=0
322 DO_HOOK_REFRESH=false
324 while [ "${COMMAND:0:1}" = "-" ] ; do
325 case "$COMMAND" in
326 -f )KEEP_GOING="||:"
329 refresh_all_hooks
330 exit 0;
332 --set-push-urls)
333 shift
334 PUSH_USER="$1"
335 if [ -n "${PUSH_USER}" ] ; then
336 PUSH_USER="${PUSH_USER}@"
338 set_push_urls "$PUSH_USER"
339 exit 0;
342 echo "option: $COMMAND not supported" 1>&2
343 exit 1
344 esac
345 shift
346 COMMAND="$1"
347 done
349 shift
351 case "$COMMAND" in
352 branch)
353 do_git_cmd "${COMMAND}" "$@"
355 checkout)
356 do_checkout "$@"
358 clone)
359 do_init_modules && refresh_all_hooks
361 fetch)
362 (git fetch "$@" && git submodule foreach git fetch "$@" ) && git submodule update --progress
365 grep)
366 KEEP_GOING="||:"
367 do_git_cmd "${COMMAND}" "$@"
369 pull)
370 git pull "$@" && git submodule update --progress && refresh_all_hooks
372 push)
373 git submodule foreach git push "$@"
374 if [ "$?" = "0" ] ; then
375 git push "$@"
378 reset)
379 do_reset
381 tag)
382 do_git_cmd "${COMMAND}" "$@"
387 echo "./g does not support command: $COMMAND" 1>&2
388 exit 1;
390 esac
392 exit $?
394 # vi:set shiftwidth=4 expandtab: