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
=$
(< config_host.mk
grep -a 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 "${COREDIR?}/.git-hooks"/* ; do
41 if [ ! -e "${hook_name}" ] ; then
44 hook
="${repo?}/.git/hooks/${hook_name##*/}"
45 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
47 ln -sf "${hook_name}" "${hook?}"
50 # override if need be by the submodules' own hooks
51 for hook_name
in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
52 if [ ! -e "${hook_name}" ] ; then
55 hook
="${repo?}/.git/hooks/${hook_name##*/}"
56 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
58 ln -sf "${hook_name}" "${hook?}"
61 elif [ -d .git
/modules
/"${repo}"/hooks
] ; then
62 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
63 if [ ! -e "${hook_name}" ] ; then
66 hook
=".git/modules/${repo?}/hooks/${hook_name##*/}"
67 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
69 ln -sf "${hook_name}" "${hook?}"
72 # override if need be by the submodules' own hooks
73 for hook_name
in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
74 if [ ! -e "${hook_name}" ] ; then
77 hook
=".git/modules/${repo?}/hooks/${hook_name##*/}"
78 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
80 ln -sf "${hook_name}" "${hook?}"
93 pushd "${COREDIR?}" > /dev
/null
94 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
95 hook
=".git/hooks/${hook_name##*/}"
96 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
98 ln -sf "${hook_name}" "${hook?}"
102 for repo
in ${SUBMODULES_ALL?} ; do
103 refresh_submodule_hooks
"$repo"
114 if [ -n "$repo" ] ; then
115 pushd "${COREDIR?}/${repo?}" > /dev
/null
117 pushd "${COREDIR?}" > /dev
/null
120 echo "setting up push url for ${repo?}"
121 if [ "${repo?}" = "helpcontent2" ] ; then
122 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/help"
124 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/${repo?}"
133 for repo
in ${SUBMODULES_ACTIVE?} ; do
134 set_push_url
"${repo?}"
138 get_active_submodules
()
143 for repo
in ${SUBMODULES_ALL?} ; do
144 if [ -d "${repo?}"/.git
] ||
[ -f "${repo?}"/.git
] ; then
145 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
150 get_configured_submodules
()
152 SUBMODULES_CONFIGURED
=""
153 if [ -f config_host.mk
] ; then
154 SUBMODULES_CONFIGURED
=$
(< config_host.mk
grep -a GIT_NEEDED_SUBMODULES |
sed -e "s/.*=//")
156 # if we need the configured submodule before the configuration is done. we assumed you want them all
157 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
164 if [ -f config_host.mk
]; then
165 REFERENCED_GIT
=$
(< config_host.mk
grep -a GIT_REFERENCE_SRC |
sed -e "s/.*=//")
168 if [ -f config_host.mk
]; then
169 LINKED_GIT
=$
(< config_host.mk
grep -a GIT_LINK_SRC |
sed -e "s/.*=//")
178 for module
in $SUBMODULES_CONFIGURED ; do
179 if [ ! -d "${module?}"/.git
] ; then
182 if [ -d clone
/help
/.git
] ; then
183 repo
="clone/help/.git"
187 if [ -d clone
/"${module?}"/.git
] ; then
188 repo
="clone/${module?}/.git"
192 if [ -n "$repo" ] ; then
193 cp -r "${repo?}" "${module?}/."
203 git submodule foreach git
"$@" $KEEP_GOING
209 local create_branch
="0"
213 git checkout
"$@" ||
return $?
215 if [ "$cmd" = "-f" ]; then
217 elif [ "$cmd" = "-b" ] ; then
219 elif [ "$create_branch" = "1" ] ; then
224 if [ -f .gitmodules
] ; then
225 git submodule update
--progress
226 if [ -n "$branch" ] ; then
227 git submodule foreach git checkout
-b "${branch}" HEAD ||
return $?
230 # now that is the nasty case we moved prior to submodules
231 # delete the submodules left over if any
232 for module
in $SUBMODULES_ALL ; do
233 echo "clean-up submodule $module"
236 # make sure we have the needed repo in clone
237 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
244 git
reset "$@" ||
return $?
245 if [ -f .gitmodules
] ; then
246 git submodule update
--progress ||
return $?
248 # now that is the nasty case we moved prior to submodules
249 # delete the submodules left over if any
250 for module
in $SUBMODULES_ALL ; do
251 echo "clean-up submodule $module"
254 # make sure we have the needed repo in clone
255 .
/g clone
&& .
/g
-f reset "$@"
267 for module
in $SUBMODULES_CONFIGURED ; do
268 if [ -n "$LINKED_GIT" ] ; then
269 if ! [ -d ".git/modules/${module}" ]; then
270 .
/bin
/git-new-module-workdir
"${LINKED_GIT}/${module}" "${module}"
273 configured
=$
(git config
--local --get submodule.
"${module}".url
)
274 if [ -z "$configured" ] ; then
275 git submodule init
"$module" ||
return $?
278 for module
in $SUBMODULES_CONFIGURED ; do
279 if [ -n "$REFERENCED_GIT" ] ; then
280 git submodule update
--reference "$REFERENCED_GIT/.git/modules/$module" --progress "$module" ||
return $?
282 git submodule update
--progress "$module" ||
return $?
289 # no params, no action
290 if [ "$#" -eq "0" ] ; then
294 if [ ! "$(type -p git)" ]; then
295 echo "Cannot find the git binary! Is git installed and is in PATH?"
300 get_active_submodules
301 get_configured_submodules
307 # extra params for some commands, like log
322 DO_HOOK_REFRESH
=false
324 while [ "${COMMAND:0:1}" = "-" ] ; do
335 if [ -n "${PUSH_USER}" ] ; then
336 PUSH_USER
="${PUSH_USER}@"
338 set_push_urls
"$PUSH_USER"
342 echo "option: $COMMAND not supported" 1>&2
353 do_git_cmd
"${COMMAND}" "$@"
359 do_init_modules
&& refresh_all_hooks
362 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
--progress
367 do_git_cmd
"${COMMAND}" "$@"
370 git pull
"$@" && git submodule update
--progress && refresh_all_hooks
373 git submodule foreach git push
"$@"
374 if [ "$?" = "0" ] ; then
382 do_git_cmd
"${COMMAND}" "$@"
387 echo "./g does not support command: $COMMAND" 1>&2
394 # vi:set shiftwidth=4 expandtab: