allow to create new database using the wizard again (fdo#62937)
[LibreOffice.git] / g
blobc24ca3bad4810eb34ab239f8c93ff77233a659e4
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=$(cat config_host.mk | grep 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 $(ls -1 ${COREDIR?}/.git-hooks) ; do
41 hook="${repo?}/.git/hooks/${hook_name?}"
42 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
43 rm -f "${hook?}"
44 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
46 done
47 # override if need be by the submodules' own hooks
48 for hook_name in $(ls -1 ${COREDIR?}/${repo?}/.git-hooks 2>/dev/null) ; do
49 hook="${repo?}/.git/hooks/${hook_name?}"
50 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
51 rm -f "${hook?}"
52 ln -sf "${COREDIR?}/${repo?}/.git-hooks/${hook_name?}" "${hook?}"
54 done
55 elif [ -d .git/modules/${repo}/hooks ] ; then
56 for hook_name in $(ls -1 ${COREDIR?}/.git-hooks) ; do
57 hook=".git/modules/${repo?}/hooks/${hook_name?}"
58 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
59 rm -f "${hook?}"
60 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
62 done
63 # override if need be by the submodules' own hooks
64 for hook_name in $(ls -1 ${COREDIR?}/${repo?}/.git-hooks 2>/dev/null) ; do
65 hook=".git/modules/${repo?}/hooks/${hook_name?}"
66 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
67 rm -f "${hook?}"
68 ln -sf "${COREDIR?}/${repo?}/.git-hooks/${hook_name?}" "${hook?}"
70 done
75 refresh_all_hooks()
77 local repo
78 local hook_name
79 local hook
81 pushd ${COREDIR?} > /dev/null
82 for hook_name in $(ls -1 ${COREDIR?}/.git-hooks) ; do
83 hook=".git/hooks/${hook_name?}"
84 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
85 rm -f "${hook?}"
86 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
88 done
90 for repo in ${SUBMODULES_ALL?} ; do
91 refresh_submodule_hooks $repo
92 done
93 popd > /dev/null
97 set_push_url()
99 local repo
101 repo="$1"
102 if [ -n "$repo" ] ; then
103 pushd "${COREDIR?}/${repo?}" > /dev/null
104 else
105 pushd "${COREDIR?}" > /dev/null
106 repo="core"
108 echo "setting up push url for ${repo?}"
109 if [ "${repo?}" = "helpcontent2" ] ; then
110 git config remote.origin.pushurl "ssh://${PUSH_USER}gerrit.libreoffice.org:29418/help"
111 else
112 git config remote.origin.pushurl "ssh://${PUSH_USER}gerrit.libreoffice.org:29418/${repo?}"
114 popd > /dev/null
117 set_push_urls()
119 PUSH_USER="$1"
120 set_push_url
121 for repo in ${SUBMODULES_ACTIVE?} ; do
122 set_push_url "${repo?}"
123 done
126 get_active_submodules()
128 SUBMODULES_ACTIVE=""
129 local repo
131 for repo in ${SUBMODULES_ALL?} ; do
132 if [ -d ${repo?}/.git ] ; then
133 SUBMODULES_ACTIVE="${repo?} ${SUBMODULES_ACTIVE?}"
135 done
138 get_configured_submodules()
140 SUBMODULES_CONFIGURED=""
141 if [ -f config_host.mk ] ; then
142 SUBMODULES_CONFIGURED=$(cat config_host.mk | grep GIT_NEEDED_SUBMODULES | sed -e "s/.*=//")
143 else
144 # if we need the configured submoduel before the configuration is done. we assumed you want them all
145 SUBMODULES_CONFIGURED=${SUBMODULES_ALL?}
149 get_git_reference()
151 REFERENCED_GIT=""
152 if [ -f config_host.mk ]; then
153 REFERENCED_GIT=$(cat config_host.mk | grep GIT_REFERENCE_SRC | sed -e "s/.*=//")
157 do_shortcut_update()
159 local module
160 local repo
162 for module in $SUBMODULES_CONFIGURED ; do
163 if [ ! -d ${module?}/.git ] ; then
164 case "${module?}" in
165 helpcontent2)
166 if [ -d clone/help/.git ] ; then
167 repo="clone/help/.git"
171 if [ -d clone/${module?}/.git ] ; then
172 repo="clone/${module?}/.git"
175 esac
176 if [ -n "$repo" ] ; then
177 cp -r "${repo?}" "${module?}/."
180 done
183 do_git_cmd()
185 echo "cmd:$@"
186 git "$@"
187 git submodule foreach git "$@" $KEEP_GOING
190 do_checkout()
192 local cmd
193 local create_branch="0"
194 local branch
195 local module
197 git checkout "$@" || return $?
198 for cmd in "$@" ; do
199 if [ "$cmd" = "-f" ]; then
200 return 0
201 elif [ "$cmd" = "-b" ] ; then
202 create_branch=1
203 elif [ "$create_branch" = "1" ] ; then
204 branch="$arg"
205 create_branch=0
207 done
208 if [ -f .gitmodules ] ; then
209 git submodule update
210 if [ -n "$branch" ] ; then
211 git submodules foreach git checkout -b ${branch} HEAD || return $?
213 else
214 # now that is the nasty case we moved prior to submodules
215 # delete the submodules left over if any
216 for module in $SUBMODULES_ALL ; do
217 echo "clean-up submodule $module"
218 rm -fr ${module}
219 done
220 # make sure we have the needed repo in clone
221 ./g clone && ./g -f checkout "$@" || return $?
223 return $?
226 do_reset()
228 git reset "$@" || return $?
229 if [ -f .gitmodules ] ; then
230 git submodule update || return $?
231 else
232 # now that is the nasty case we moved prior to submodules
233 # delete the submodules left over if any
234 for module in $SUBMODULES_ALL ; do
235 echo "clean-up submodule $module"
236 rm -fr ${module}
237 done
238 # make sure we have the needed repo in clone
239 ./g clone && ./g -f reset "$@"
241 return $?;
244 do_init_modules()
246 local module
247 local configured
249 do_shortcut_update
251 for module in $SUBMODULES_CONFIGURED ; do
252 configured=$(git config --local --get submodule.${module}.url)
253 if [ -z "$configured" ] ; then
254 git submodule init $module || return $?
256 done
257 for module in $SUBMODULES_CONFIGURED ; do
258 if [ -n "$REFERENCED_GIT" ] ; then
259 git submodule update --reference $REFERENCED_GIT/.git/modules/$module $module || return $?
260 else
261 git submodule update $module || return $?
263 done
264 return 0
268 # no params, no action
269 if [ "$#" -eq "0" ] ; then
270 usage
273 if [ ! "`type -p git`" ]; then
274 echo "Cannot find the git binary! Is git installed and is in PATH?"
275 exit 1
279 get_active_submodules
280 get_configured_submodules
281 get_git_reference
286 # extra params for some commands, like log
287 EXTRA=
288 COMMAND="$1"
289 PAGER=
290 RELATIVIZE=1
291 PUSH_ALL=
292 PUSH_USER=
293 PUSH_NOTES=
294 LAST_WORKING=
295 SET_LAST_WORKING=
296 ALLOW_EMPTY=
297 KEEP_GOING=
298 REPORT_REPOS=1
299 REPORT_COMMANDS=0
300 REPORT_COMPACT=0
301 DO_HOOK_REFRESH=false
303 while [ "${COMMAND:0:1}" = "-" ] ; do
304 case "$COMMAND" in
305 -f )KEEP_GOING="||:"
308 refresh_all_hooks
309 exit 0;
311 --set-push-urls)
312 shift
313 PUSH_USER="$1"
314 if [ -n "${PUSH_USER}" ] ; then
315 PUSH_USER="${PUSH_USER}@"
317 set_push_urls "$PUSH_USER"
318 exit 0;
321 echo "option: $COMMAND not supported" 1>&2
322 exit 1
323 esac
324 shift
325 COMMAND="$1"
326 done
328 shift
330 case "$COMMAND" in
331 branch)
332 do_git_cmd ${COMMAND} "$@"
334 checkout)
335 do_checkout "$@"
337 clone)
338 do_init_modules && refresh_all_hooks
340 fetch)
341 (git fetch "$@" && git submodule foreach git fetch "$@" ) && git submodule update
344 grep)
345 KEEP_GOING="||:"
346 do_git_cmd ${COMMAND} "$@"
348 pull)
349 git pull "$@" && git submodule update && refresh_all_hooks
351 push)
352 git submodule foreach git push "$@"
353 if [ "$?" = "0" ] ; then
354 git push "$@"
357 reset)
358 do_reset
360 tag)
361 do_git_cmd ${COMMAND} "$@"
366 echo "./g does not support command: $COMMAND" 1>&2
367 exit 1;
369 esac
371 exit $?
373 # vi:set shiftwidth=4 expandtab: