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?}
130 for module
in $SUBMODULES_CONFIGURED ; do
131 if [ ! -d ${module?}/.git
] ; then
134 if [ -d clone
/help
/.git
] ; then
135 repo
="clone/help/.git"
139 if [ -d clone
/${module?}/.git
] ; then
140 repo
="clone/${module?}/.git"
144 if [ -n "$repo" ] ; then
145 cp -r "${repo?}" "${module?}/."
155 git submodule foreach git
"$@" $KEEP_GOING
161 local create_branch
="0"
165 git checkout
"$@" ||
return $?
167 if [ "$cmd" = "-f" ]; then
169 elif [ "$cmd" = "-b" ] ; then
171 elif [ "$create_branch" = "1" ] ; then
176 if [ -f .gitmodules
] ; then
178 if [ -n "$branch" ] ; then
179 git submodules foreach git checkout
-b ${branch} HEAD ||
return $?
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"
188 # make sure we have the needed repo in clone
189 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
196 git
reset "$@" ||
return $?
197 if [ -f .gitmodules
] ; then
198 git submodule update ||
return $?
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"
206 # make sure we have the needed repo in clone
207 .
/g clone
&& .
/g
-f reset "$@"
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 $?
229 # no params, no action
230 if [ "$#" -eq "0" ] ; then
234 if [ ! "`type -p git`" ]; then
235 echo "Cannot find the git binary! Is git installed and is in PATH?"
240 get_active_submodules
241 get_configured_submodules
246 # extra params for some commands, like log
261 DO_HOOK_REFRESH
=false
263 while [ "${COMMAND:0:1}" = "-" ] ; do
274 if [ -n "${PUSH_USER}" ] ; then
275 PUSH_USER
="${PUSH_USER}@"
277 set_push_urls
"$PUSH_USER"
281 echo "option: $COMMAND not supported" 1>&2
292 do_git_cmd
${COMMAND} "$@"
298 do_init_modules
&& git submodule update
&& refresh_all_hooks
301 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
306 do_git_cmd
${COMMAND} "$@"
309 git pull
"$@" && git submodule update
&& refresh_all_hooks
312 git submodule foreach git push
"$@"
313 if [ "$?" = "0" ] ; then
321 do_git_cmd
${COMMAND} "$@"
326 echo "./g does not support command: $COMMAND" 1>&2
333 # vi:set shiftwidth=4 expandtab: