Updated core
[LibreOffice.git] / g
blob288489cfd2f830435b23b8ef37b4a7e1f26b8d0b
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 set_push_url
97 for repo in ${SUBMODULES_ACTIVE?} ; do
98 set_push_url "${repo?}"
99 done
102 get_active_submodules()
104 SUBMODULES_ACTIVE=""
105 local repo
107 for repo in ${SUBMODULES_ALL?} ; do
108 if [ -d ${repo?}/.git ] ; then
109 SUBMODULES_ACTIVE="${repo?} ${SUBMODULES_ACTIVE?}"
111 done
114 get_configured_submodules()
116 SUBMODULES_CONFIGURED=""
117 if [ -f "config_host.mk" ] ; then
118 SUBMODULES_CONFIGURED=$(cat config_host.mk | grep GIT_NEEDED_SUBMODULES | sed -e "s/.*=//")
119 else
120 # if we need the configured submoduel before the configuration is done. we assumed you want them all
121 SUBMODULES_CONFIGURED=${SUBMODULES_ALL?}
125 do_shortcut_update()
127 local module
128 local repo
130 for module in $SUBMODULES_CONFIGURED ; do
131 if [ ! -d ${module?}/.git ] ; then
132 case "${module?}" in
133 helpcontent2)
134 if [ -d clone/help/.git ] ; then
135 repo="clone/help/.git"
139 if [ -d clone/${module?}/.git ] ; then
140 repo="clone/${module?}/.git"
143 esac
144 if [ -n "$repo" ] ; then
145 cp -r "${repo?}" "${module?}/."
148 done
151 do_git_cmd()
153 echo "cmd:$@"
154 git "$@"
155 git submodule foreach git "$@" $KEEP_GOING
158 do_checkout()
160 local cmd
161 local create_branch="0"
162 local branch
163 local module
165 git checkout "$@" || return $?
166 for cmd in "$@" ; do
167 if [ "$cmd" = "-f" ]; then
168 return 0
169 elif [ "$cmd" = "-b" ] ; then
170 create_branch=1
171 elif [ "$create_branch" = "1" ] ; then
172 branch="$arg"
173 create_branch=0
175 done
176 if [ -f .gitmodules ] ; then
177 git submodule update
178 if [ -n "$branch" ] ; then
179 git submodules foreach git checkout -b ${branch} HEAD || return $?
181 else
182 # now that is the nasty case we moved prior to submodules
183 # delete the submodules left over if any
184 for module in $SUBMODULES_ALL ; do
185 echo "clean-up submodule $module"
186 rm -fr ${module}
187 done
188 # make sure we have the needed repo in clone
189 ./g clone && ./g -f checkout "$@" || return $?
191 return $?
194 do_reset()
196 git reset "$@" || return $?
197 if [ -f .gitmodules ] ; then
198 git submodule update || return $?
199 else
200 # now that is the nasty case we moved prior to submodules
201 # delete the submodules left over if any
202 for module in $SUBMODULES_ALL ; do
203 echo "clean-up submodule $module"
204 rm -fr ${module}
205 done
206 # make sure we have the needed repo in clone
207 ./g clone && ./g -f reset "$@"
209 return $?;
212 do_init_modules()
214 local module
215 local configured
217 do_shortcut_update
219 for module in $SUBMODULES_CONFIGURED ; do
220 configured=$(git config --local --get submodule.${module}.url)
221 if [ -z "$configured" ] ; then
222 git submodule init $module || return $?
224 done
225 return 0
229 # no params, no action
230 if [ "$#" -eq "0" ] ; then
231 usage
234 if [ ! "`type -p git`" ]; then
235 echo "Cannot find the git binary! Is git installed and is in PATH?"
236 exit 1
240 get_active_submodules
241 get_configured_submodules
246 # extra params for some commands, like log
247 EXTRA=
248 COMMAND="$1"
249 PAGER=
250 RELATIVIZE=1
251 PUSH_ALL=
252 PUSH_USER=
253 PUSH_NOTES=
254 LAST_WORKING=
255 SET_LAST_WORKING=
256 ALLOW_EMPTY=
257 KEEP_GOING=
258 REPORT_REPOS=1
259 REPORT_COMMANDS=0
260 REPORT_COMPACT=0
261 DO_HOOK_REFRESH=false
263 while [ "${COMMAND:0:1}" = "-" ] ; do
264 case "$COMMAND" in
265 -f )KEEP_GOING="||:"
268 refresh_all_hooks
269 exit 0;
271 --set-push-urls)
272 shift
273 PUSH_USER="$1"
274 if [ -n "${PUSH_USER}" ] ; then
275 PUSH_USER="${PUSH_USER}@"
277 set_push_urls "$PUSH_USER"
278 exit 0;
281 echo "option: $COMMAND not supported" 1>&2
282 exit 1
283 esac
284 shift
285 COMMAND="$1"
286 done
288 shift
290 case "$COMMAND" in
291 branch)
292 do_git_cmd ${COMMAND} "$@"
294 checkout)
295 do_checkout "$@"
297 clone)
298 do_init_modules && git submodule update && refresh_all_hooks
300 fetch)
301 (git fetch "$@" && git submodule foreach git fetch "$@" ) && git submodule update
304 grep)
305 KEEP_GOING="||:"
306 do_git_cmd ${COMMAND} "$@"
308 pull)
309 git pull "$@" && git submodule update && refresh_all_hooks
311 push)
312 git submodule foreach git push "$@"
313 if [ "$?" = "0" ] ; then
314 git push "$@"
317 reset)
318 do_reset
320 tag)
321 do_git_cmd ${COMMAND} "$@"
326 echo "./g does not support command: $COMMAND" 1>&2
327 exit 1;
329 esac
331 exit $?
333 # vi:set shiftwidth=4 expandtab: