3 # Wrapper for git to handle more subdirs at the same time
6 if [ -n "$g_debug" ] ; then
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/.*=//")
27 echo "Usage: g [options] [git (checkout|clone|fetch|grep|pull|push|reset) [git options/args..]]"
29 echo " -z restore the git hooks and do other sanity checks"
32 refresh_submodule_hooks
()
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
44 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
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
52 ln -sf "${COREDIR?}/${repo?}/.git-hooks/${hook_name?}" "${hook?}"
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
60 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
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
68 ln -sf "${COREDIR?}/${repo?}/.git-hooks/${hook_name?}" "${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
86 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
90 for repo
in ${SUBMODULES_ALL?} ; do
91 refresh_submodule_hooks
$repo
102 if [ -n "$repo" ] ; then
103 pushd "${COREDIR?}/${repo?}" > /dev
/null
105 pushd "${COREDIR?}" > /dev
/null
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"
112 git config remote.origin.pushurl
"ssh://${PUSH_USER}gerrit.libreoffice.org:29418/${repo?}"
121 for repo
in ${SUBMODULES_ACTIVE?} ; do
122 set_push_url
"${repo?}"
126 get_active_submodules
()
131 for repo
in ${SUBMODULES_ALL?} ; do
132 if [ -d ${repo?}/.git
] ; then
133 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
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/.*=//")
144 # if we need the configured submoduel before the configuration is done. we assumed you want them all
145 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
152 if [ -f config_host.mk
]; then
153 REFERENCED_GIT
=$
(cat config_host.mk |
grep GIT_REFERENCE_SRC |
sed -e "s/.*=//")
162 for module
in $SUBMODULES_CONFIGURED ; do
163 if [ ! -d ${module?}/.git
] ; then
166 if [ -d clone
/help
/.git
] ; then
167 repo
="clone/help/.git"
171 if [ -d clone
/${module?}/.git
] ; then
172 repo
="clone/${module?}/.git"
176 if [ -n "$repo" ] ; then
177 cp -r "${repo?}" "${module?}/."
187 git submodule foreach git
"$@" $KEEP_GOING
193 local create_branch
="0"
197 git checkout
"$@" ||
return $?
199 if [ "$cmd" = "-f" ]; then
201 elif [ "$cmd" = "-b" ] ; then
203 elif [ "$create_branch" = "1" ] ; then
208 if [ -f .gitmodules
] ; then
210 if [ -n "$branch" ] ; then
211 git submodules foreach git checkout
-b ${branch} HEAD ||
return $?
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"
220 # make sure we have the needed repo in clone
221 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
228 git
reset "$@" ||
return $?
229 if [ -f .gitmodules
] ; then
230 git submodule update ||
return $?
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"
238 # make sure we have the needed repo in clone
239 .
/g clone
&& .
/g
-f reset "$@"
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 $?
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 $?
261 git submodule update
$module ||
return $?
268 # no params, no action
269 if [ "$#" -eq "0" ] ; then
273 if [ ! "`type -p git`" ]; then
274 echo "Cannot find the git binary! Is git installed and is in PATH?"
279 get_active_submodules
280 get_configured_submodules
286 # extra params for some commands, like log
301 DO_HOOK_REFRESH
=false
303 while [ "${COMMAND:0:1}" = "-" ] ; do
314 if [ -n "${PUSH_USER}" ] ; then
315 PUSH_USER
="${PUSH_USER}@"
317 set_push_urls
"$PUSH_USER"
321 echo "option: $COMMAND not supported" 1>&2
332 do_git_cmd
${COMMAND} "$@"
338 do_init_modules
&& refresh_all_hooks
341 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
346 do_git_cmd
${COMMAND} "$@"
349 git pull
"$@" && git submodule update
&& refresh_all_hooks
352 git submodule foreach git push
"$@"
353 if [ "$?" = "0" ] ; then
361 do_git_cmd
${COMMAND} "$@"
366 echo "./g does not support command: $COMMAND" 1>&2
373 # vi:set shiftwidth=4 expandtab: