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
20 echo "Usage: g [options] [git (checkout|clone|fetch|grep|pull|push|reset) [git options/args..]]"
22 echo " -z restore the git hooks and do other sanity checks"
25 refresh_submodule_hooks
()
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
37 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
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
45 ln -sf "${COREDIR?}/${repo?}/.git-hooks/${hook_name?}" "${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
62 ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
66 for repo
in ${SUBMODULES_ALL?} ; do
67 refresh_submodule_hooks
$repo
78 if [ -n "$repo" ] ; then
79 pushd "${COREDIR?}/${repo?}" > /dev
/null
81 pushd "${COREDIR?}" > /dev
/null
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"
88 git config remote.origin.pushurl
"ssh://${PUSH_USER}gerrit.libreoffice.org:29418/${repo?}"
96 if [ -n "$PUSH_USER" ] ; then
97 PUSH_USER
="${PUSH_USER}@"
100 for repo
in ${SUBMODULES_ACTIVE?} ; do
101 set_push_url
"${repo?}"
105 get_active_submodules
()
110 for repo
in ${SUBMODULES_ALL?} ; do
111 if [ -d ${repo?}/.git
] ; then
112 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
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/.*=//")
123 # if we need the configured submoduel before the configuration is done. we assumed you want them all
124 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
133 for module
in $SUBMODULES_CONFIGURED ; do
134 if [ ! -d ${module?}/.git
] ; then
137 if [ -d clone
/help
/.git
] ; then
138 repo
="clone/help/.git"
142 if [ -d clone
/${module?}/.git
] ; then
143 repo
="clone/${module?}/.git"
147 if [ -n "$repo" ] ; then
148 cp -r "${repo?}" "${module?}/."
158 git submodule foreach git
"$@" $KEEP_GOING
164 local create_branch
="0"
168 git checkout
"$@" ||
return $?
170 if [ "$cmd" = "-f" ]; then
172 elif [ "$cmd" = "-b" ] ; then
174 elif [ "$create_branch" = "1" ] ; then
179 if [ -f .gitmodules
] ; then
181 if [ -n "$branch" ] ; then
182 git submodules foreach git checkout
-b ${branch} HEAD ||
return $?
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"
191 # make sure we have the needed repo in clone
192 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
199 git
reset "$@" ||
return $?
200 if [ -f .gitmodules
] ; then
201 git submodule update ||
return $?
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"
209 # make sure we have the needed repo in clone
210 .
/g clone
&& .
/g
-f reset "$@"
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 $?
232 # no params, no action
233 if [ "$#" -eq "0" ] ; then
237 if [ ! "`type -p git`" ]; then
238 echo "Cannot find the git binary! Is git installed and is in PATH?"
243 get_active_submodules
244 get_configured_submodules
249 # extra params for some commands, like log
264 DO_HOOK_REFRESH
=false
266 while [ "${COMMAND:0:1}" = "-" ] ; do
277 if [ -n "${PUSH_USER}" ] ; then
278 PUSH_USER
="${PUSH_USER}@"
284 echo "option: $COMMAND not supported" 1>&2
295 do_git_cmd
${COMMAND} "$@"
301 do_init_modules
&& git submodule update
&& refresh_all_hooks
304 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
309 do_git_cmd
${COMMAND} "$@"
312 git pull
"$@" && git submodule update
&& refresh_all_hooks
315 git submodule foreach git push
"$@"
316 if [ "$?" = "0" ] ; then
324 do_git_cmd
${COMMAND} "$@"
329 echo "./g does not support command: $COMMAND" 1>&2
336 # vi:set shiftwidth=4 expandtab: