get rid of custom all-caps ui widget
[LibreOffice.git] / g
blob0d899b4a7fe280d4f10ba492fc366815e3d98cf1
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 # In our workflow, it's always gerrit that does the submodule updates, so
94 # better ignoring them to avoid accidentally including those changes in our
95 # commits.
96 # 'git submodule status' can be still used to see if a submodule has such
97 # changes.
98 for repo in ${SUBMODULES_CONFIGURED?} ; do
99 git config submodule.$repo.ignore all
100 done
101 popd > /dev/null
105 set_push_url()
107 local repo
109 repo="$1"
110 if [ -n "$repo" ] ; then
111 pushd "${COREDIR?}/${repo?}" > /dev/null
112 else
113 pushd "${COREDIR?}" > /dev/null
114 repo="core"
116 echo "setting up push url for ${repo?}"
117 if [ "${repo?}" = "helpcontent2" ] ; then
118 git config remote.origin.pushurl "ssh://${PUSH_USER}logerrit/help"
119 else
120 git config remote.origin.pushurl "ssh://${PUSH_USER}logerrit/${repo?}"
122 popd > /dev/null
125 set_push_urls()
127 PUSH_USER="$1"
128 set_push_url
129 for repo in ${SUBMODULES_ACTIVE?} ; do
130 set_push_url "${repo?}"
131 done
134 get_active_submodules()
136 SUBMODULES_ACTIVE=""
137 local repo
139 for repo in ${SUBMODULES_ALL?} ; do
140 if [ -d ${repo?}/.git -o -f ${repo?}/.git ] ; then
141 SUBMODULES_ACTIVE="${repo?} ${SUBMODULES_ACTIVE?}"
143 done
146 get_configured_submodules()
148 SUBMODULES_CONFIGURED=""
149 if [ -f config_host.mk ] ; then
150 SUBMODULES_CONFIGURED=$(cat config_host.mk | grep GIT_NEEDED_SUBMODULES | sed -e "s/.*=//")
151 else
152 # if we need the configured submoduel before the configuration is done. we assumed you want them all
153 SUBMODULES_CONFIGURED=${SUBMODULES_ALL?}
157 get_git_reference()
159 REFERENCED_GIT=""
160 if [ -f config_host.mk ]; then
161 REFERENCED_GIT=$(cat config_host.mk | grep GIT_REFERENCE_SRC | sed -e "s/.*=//")
163 LINKED_GIT=""
164 if [ -f config_host.mk ]; then
165 LINKED_GIT=$(cat config_host.mk | grep GIT_LINK_SRC | sed -e "s/.*=//")
169 do_shortcut_update()
171 local module
172 local repo
174 for module in $SUBMODULES_CONFIGURED ; do
175 if [ ! -d ${module?}/.git ] ; then
176 case "${module?}" in
177 helpcontent2)
178 if [ -d clone/help/.git ] ; then
179 repo="clone/help/.git"
183 if [ -d clone/${module?}/.git ] ; then
184 repo="clone/${module?}/.git"
187 esac
188 if [ -n "$repo" ] ; then
189 cp -r "${repo?}" "${module?}/."
192 done
195 do_git_cmd()
197 echo "cmd:$@"
198 git "$@"
199 git submodule foreach git "$@" $KEEP_GOING
202 do_checkout()
204 local cmd
205 local create_branch="0"
206 local branch
207 local module
209 git checkout "$@" || return $?
210 for cmd in "$@" ; do
211 if [ "$cmd" = "-f" ]; then
212 return 0
213 elif [ "$cmd" = "-b" ] ; then
214 create_branch=1
215 elif [ "$create_branch" = "1" ] ; then
216 branch="$arg"
217 create_branch=0
219 done
220 if [ -f .gitmodules ] ; then
221 git submodule update
222 if [ -n "$branch" ] ; then
223 git submodules foreach git checkout -b ${branch} HEAD || return $?
225 else
226 # now that is the nasty case we moved prior to submodules
227 # delete the submodules left over if any
228 for module in $SUBMODULES_ALL ; do
229 echo "clean-up submodule $module"
230 rm -fr ${module}
231 done
232 # make sure we have the needed repo in clone
233 ./g clone && ./g -f checkout "$@" || return $?
235 return $?
238 do_reset()
240 git reset "$@" || return $?
241 if [ -f .gitmodules ] ; then
242 git submodule update || return $?
243 else
244 # now that is the nasty case we moved prior to submodules
245 # delete the submodules left over if any
246 for module in $SUBMODULES_ALL ; do
247 echo "clean-up submodule $module"
248 rm -fr ${module}
249 done
250 # make sure we have the needed repo in clone
251 ./g clone && ./g -f reset "$@"
253 return $?;
256 do_init_modules()
258 local module
259 local configured
261 do_shortcut_update
263 for module in $SUBMODULES_CONFIGURED ; do
264 if [ -n "$LINKED_GIT" ] ; then
265 if ! [ -d ".git/modules/${module}" ]; then
266 ./bin/git-new-module-workdir "${LINKED_GIT}/${module}" "${module}"
269 configured=$(git config --local --get submodule.${module}.url)
270 if [ -z "$configured" ] ; then
271 git submodule init $module || return $?
273 done
274 for module in $SUBMODULES_CONFIGURED ; do
275 if [ -n "$REFERENCED_GIT" ] ; then
276 git submodule update --reference $REFERENCED_GIT/.git/modules/$module $module || return $?
277 else
278 git submodule update $module || return $?
280 done
281 return 0
285 # no params, no action
286 if [ "$#" -eq "0" ] ; then
287 usage
290 if [ ! "`type -p git`" ]; then
291 echo "Cannot find the git binary! Is git installed and is in PATH?"
292 exit 1
296 get_active_submodules
297 get_configured_submodules
298 get_git_reference
303 # extra params for some commands, like log
304 EXTRA=
305 COMMAND="$1"
306 PAGER=
307 RELATIVIZE=1
308 PUSH_ALL=
309 PUSH_USER=
310 PUSH_NOTES=
311 LAST_WORKING=
312 SET_LAST_WORKING=
313 ALLOW_EMPTY=
314 KEEP_GOING=
315 REPORT_REPOS=1
316 REPORT_COMMANDS=0
317 REPORT_COMPACT=0
318 DO_HOOK_REFRESH=false
320 while [ "${COMMAND:0:1}" = "-" ] ; do
321 case "$COMMAND" in
322 -f )KEEP_GOING="||:"
325 refresh_all_hooks
326 exit 0;
328 --set-push-urls)
329 shift
330 PUSH_USER="$1"
331 if [ -n "${PUSH_USER}" ] ; then
332 PUSH_USER="${PUSH_USER}@"
334 set_push_urls "$PUSH_USER"
335 exit 0;
338 echo "option: $COMMAND not supported" 1>&2
339 exit 1
340 esac
341 shift
342 COMMAND="$1"
343 done
345 shift
347 case "$COMMAND" in
348 branch)
349 do_git_cmd ${COMMAND} "$@"
351 checkout)
352 do_checkout "$@"
354 clone)
355 do_init_modules && refresh_all_hooks
357 fetch)
358 (git fetch "$@" && git submodule foreach git fetch "$@" ) && git submodule update
361 grep)
362 KEEP_GOING="||:"
363 do_git_cmd ${COMMAND} "$@"
365 pull)
366 git pull "$@" && git submodule update && refresh_all_hooks
368 push)
369 git submodule foreach git push "$@"
370 if [ "$?" = "0" ] ; then
371 git push "$@"
374 reset)
375 do_reset
377 tag)
378 do_git_cmd ${COMMAND} "$@"
383 echo "./g does not support command: $COMMAND" 1>&2
384 exit 1;
386 esac
388 exit $?
390 # vi:set shiftwidth=4 expandtab: