lo-pack-sources: use the same top-level directory in all tarballs
[LibreOffice.git] / g
blob0ca04dd6749fe46c050f70e84388a776ee5a4f98
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 COREDIR=$(pwd)
14 popd > /dev/null
16 usage()
18 git
19 echo
20 echo "Usage: g [options] [git (checkout|clone|fetch|grep|pull|push|reset) [git options/args..]]"
21 echo ""
22 echo " -z restore the git hooks and do other sanity checks"
25 refresh_submodule_hooks()
27 local repo=$1
28 local hook
29 local hook_name
31 if [ -d ${repo?}/.git ] ; then
32 # use core's hook by default
33 for hook_name in $(ls -1 ${COREDIR?}/.git-hooks) ; do
34 hook="${repo?}/.git/hooks/${hook_name?}"
35 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
36 rm -f "${hook?}"
37 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
39 done
40 # override if need be by the submodules' own hooks
41 for hook_name in $(ls -1 ${COREDIR?}/${repo?}/.git-hooks 2>/dev/null) ; do
42 hook="${repo?}/.git/hooks/${hook_name?}"
43 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
44 rm -f "${hook?}"
45 ln -sf "${COREDIR?}/${repo?}/.git-hooks/${hook_name?}" "${hook?}"
47 done
51 refresh_all_hooks()
53 local repo
54 local hook_name
55 local hook
57 pushd ${COREDIR?} > /dev/null
58 for hook_name in $(ls -1 ${COREDIR?}/.git-hooks) ; do
59 hook=".git/hooks/${hook_name?}"
60 if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
61 rm -f "${hook?}"
62 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
64 done
66 for repo in ${SUBMODULES_ALL?} ; do
67 refresh_submodule_hooks $repo
68 done
69 popd > /dev/null
73 set_push_url()
75 local repo
77 repo="$1"
78 if [ -n "$repo" ] ; then
79 pushd "${COREDIR?}/${repo?}" > /dev/null
80 else
81 pushd "${COREDIR?}" > /dev/null
82 repo="core"
84 echo "setting up push url for ${repo?}"
85 if [ "${repo?}" = "helpcontent2" ] ; then
86 git config remote.origin.pushurl "ssh://${PUSH_USER}gerrit.libreoffice.org:29418/help"
87 else
88 git config remote.origin.pushurl "ssh://${PUSH_USER}gerrit.libreoffice.org:29418/${repo?}"
90 popd > /dev/null
93 set_push_urls()
95 PUSH_USER="$1"
96 if [ -n "$PUSH_USER" ] ; then
97 PUSH_USER="${PUSH_USER}@"
99 set_push_url
100 for repo in ${SUBMODULES_ACTIVE?} ; do
101 set_push_url "${repo?}"
102 done
105 get_active_submodules()
107 SUBMODULES_ACTIVE=""
108 local repo
110 for repo in ${SUBMODULES_ALL?} ; do
111 if [ -d ${repo?}/.git ] ; then
112 SUBMODULES_ACTIVE="${repo?} ${SUBMODULES_ACTIVE?}"
114 done
117 get_configured_submodules()
119 SUBMODULES_CONFIGURED=""
120 if [ -f "config_host.mk" ] ; then
121 SUBMODULES_CONFIGURED=$(cat config_host.mk | grep GIT_NEEDED_SUBMODULES | sed -e "s/.*=//")
122 else
123 # if we need the configured submoduel before the configuration is done. we assumed you want them all
124 SUBMODULES_CONFIGURED=${SUBMODULES_ALL?}
128 do_shortcut_update()
130 local module
131 local repo
133 for module in $SUBMODULES_CONFIGURED ; do
134 if [ ! -d ${module?}/.git ] ; then
135 case "${module?}" in
136 helpcontent2)
137 if [ -d clone/help/.git ] ; then
138 repo="clone/help/.git"
142 if [ -d clone/${module?}/.git ] ; then
143 repo="clone/${module?}/.git"
146 esac
147 if [ -n "$repo" ] ; then
148 cp -r "${repo?}" "${module?}/."
151 done
154 do_git_cmd()
156 echo "cmd:$@"
157 git "$@"
158 git submodule foreach git "$@" $KEEP_GOING
161 do_checkout()
163 local cmd
164 local create_branch="0"
165 local branch
166 local module
168 git checkout "$@" || return $?
169 for cmd in "$@" ; do
170 if [ "$cmd" = "-f" ]; then
171 return 0
172 elif [ "$cmd" = "-b" ] ; then
173 create_branch=1
174 elif [ "$create_branch" = "1" ] ; then
175 branch="$arg"
176 create_branch=0
178 done
179 if [ -f .gitmodules ] ; then
180 git submodule update
181 if [ -n "$branch" ] ; then
182 git submodules foreach git checkout -b ${branch} HEAD || return $?
184 else
185 # now that is the nasty case we moved prior to submodules
186 # delete the submodules left over if any
187 for module in $SUBMODULES_ALL ; do
188 echo "clean-up submodule $module"
189 rm -fr ${module}
190 done
191 # make sure we have the needed repo in clone
192 ./g clone && ./g -f checkout "$@" || return $?
194 return $?
197 do_reset()
199 git reset "$@" || return $?
200 if [ -f .gitmodules ] ; then
201 git submodule update || return $?
202 else
203 # now that is the nasty case we moved prior to submodules
204 # delete the submodules left over if any
205 for module in $SUBMODULES_ALL ; do
206 echo "clean-up submodule $module"
207 rm -fr ${module}
208 done
209 # make sure we have the needed repo in clone
210 ./g clone && ./g -f reset "$@"
212 return $?;
215 do_init_modules()
217 local module
218 local configured
220 do_shortcut_update
222 for module in $SUBMODULES_CONFIGURED ; do
223 configured=$(git config --local --get submodule.${module}.url)
224 if [ -z "$configured" ] ; then
225 git submodule init $module || return $?
227 done
228 return 0
232 # no params, no action
233 if [ "$#" -eq "0" ] ; then
234 usage
237 if [ ! "`type -p git`" ]; then
238 echo "Cannot find the git binary! Is git installed and is in PATH?"
239 exit 1
243 get_active_submodules
244 get_configured_submodules
249 # extra params for some commands, like log
250 EXTRA=
251 COMMAND="$1"
252 PAGER=
253 RELATIVIZE=1
254 PUSH_ALL=
255 PUSH_USER=
256 PUSH_NOTES=
257 LAST_WORKING=
258 SET_LAST_WORKING=
259 ALLOW_EMPTY=
260 KEEP_GOING=
261 REPORT_REPOS=1
262 REPORT_COMMANDS=0
263 REPORT_COMPACT=0
264 DO_HOOK_REFRESH=false
266 while [ "${COMMAND:0:1}" = "-" ] ; do
267 case "$COMMAND" in
268 -f )KEEP_GOING="||:"
271 refresh_all_hooks
272 exit 0;
274 --set-push-urls)
275 shift
276 PUSH_USER="$1"
277 if [ -n "${PUSH_USER}" ] ; then
278 PUSH_USER="${PUSH_USER}@"
280 set_push_urls
281 exit 0;
284 echo "option: $COMMAND not supported" 1>&2
285 exit 1
286 esac
287 shift
288 COMMAND="$1"
289 done
291 shift
293 case "$COMMAND" in
294 branch)
295 do_git_cmd ${COMMAND} "$@"
297 checkout)
298 do_checkout "$@"
300 clone)
301 do_init_modules && git submodule update && refresh_all_hooks
303 fetch)
304 (git fetch "$@" && git submodule foreach git fetch "$@" ) && git submodule update
307 grep)
308 KEEP_GOING="||:"
309 do_git_cmd ${COMMAND} "$@"
311 pull)
312 git pull "$@" && git submodule update && refresh_all_hooks
314 push)
315 git submodule foreach git push "$@"
316 if [ "$?" = "0" ] ; then
317 git push "$@"
320 reset)
321 do_reset
323 tag)
324 do_git_cmd ${COMMAND} "$@"
329 echo "./g does not support command: $COMMAND" 1>&2
330 exit 1;
332 esac
334 exit $?
336 # vi:set shiftwidth=4 expandtab: