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?}"
97 for repo
in ${SUBMODULES_ACTIVE?} ; do
98 set_push_url
"${repo?}"
102 get_active_submodules
()
107 for repo
in ${SUBMODULES_ALL?} ; do
108 if [ -d ${repo?}/.git
] ; then
109 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
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/.*=//")
120 # if we need the configured submoduel before the configuration is done. we assumed you want them all
121 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
128 if [ -f config_host.mk
]; then
129 REFERENCED_GIT
=$
(cat config_host.mk |
grep GIT_REFERENCE_SRC |
sed -e "s/.*=//")
138 for module
in $SUBMODULES_CONFIGURED ; do
139 if [ ! -d ${module?}/.git
] ; then
142 if [ -d clone
/help
/.git
] ; then
143 repo
="clone/help/.git"
147 if [ -d clone
/${module?}/.git
] ; then
148 repo
="clone/${module?}/.git"
152 if [ -n "$repo" ] ; then
153 cp -r "${repo?}" "${module?}/."
163 git submodule foreach git
"$@" $KEEP_GOING
169 local create_branch
="0"
173 git checkout
"$@" ||
return $?
175 if [ "$cmd" = "-f" ]; then
177 elif [ "$cmd" = "-b" ] ; then
179 elif [ "$create_branch" = "1" ] ; then
184 if [ -f .gitmodules
] ; then
186 if [ -n "$branch" ] ; then
187 git submodules foreach git checkout
-b ${branch} HEAD ||
return $?
190 # now that is the nasty case we moved prior to submodules
191 # delete the submodules left over if any
192 for module
in $SUBMODULES_ALL ; do
193 echo "clean-up submodule $module"
196 # make sure we have the needed repo in clone
197 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
204 git
reset "$@" ||
return $?
205 if [ -f .gitmodules
] ; then
206 git submodule update ||
return $?
208 # now that is the nasty case we moved prior to submodules
209 # delete the submodules left over if any
210 for module
in $SUBMODULES_ALL ; do
211 echo "clean-up submodule $module"
214 # make sure we have the needed repo in clone
215 .
/g clone
&& .
/g
-f reset "$@"
227 for module
in $SUBMODULES_CONFIGURED ; do
228 configured
=$
(git config
--local --get submodule.
${module}.url
)
229 if [ -z "$configured" ] ; then
230 git submodule init
$module ||
return $?
233 if [ -n "$REFERENCED_GIT" ] ; then
234 for module
in $SUBMODULES_CONFIGURED ; do
235 git submodule update
--reference $REFERENCED_GIT/.git
/modules
/$module $module ||
return $?
242 # no params, no action
243 if [ "$#" -eq "0" ] ; then
247 if [ ! "`type -p git`" ]; then
248 echo "Cannot find the git binary! Is git installed and is in PATH?"
253 get_active_submodules
254 get_configured_submodules
260 # extra params for some commands, like log
275 DO_HOOK_REFRESH
=false
277 while [ "${COMMAND:0:1}" = "-" ] ; do
288 if [ -n "${PUSH_USER}" ] ; then
289 PUSH_USER
="${PUSH_USER}@"
291 set_push_urls
"$PUSH_USER"
295 echo "option: $COMMAND not supported" 1>&2
306 do_git_cmd
${COMMAND} "$@"
312 do_init_modules
&& refresh_all_hooks
315 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
320 do_git_cmd
${COMMAND} "$@"
323 git pull
"$@" && git submodule update
&& refresh_all_hooks
326 git submodule foreach git push
"$@"
327 if [ "$?" = "0" ] ; then
335 do_git_cmd
${COMMAND} "$@"
340 echo "./g does not support command: $COMMAND" 1>&2
347 # vi:set shiftwidth=4 expandtab: