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 ${BUILDDIR}/config_host.mk
] ; then
14 # we are in the SRCDIR
15 SRC_ROOT
=$
(< ${BUILDDIR}/config_host.mk
grep -a SRC_ROOT |
sed -e "s/.*=//")
27 echo "Usage: g [options] [git (checkout|clone|fetch|gc|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 # There's no ".git" e.g. in a secondary worktree
95 if [ -d ".git" ]; then
96 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
97 hook
=".git/hooks/${hook_name##*/}"
98 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
100 ln -sf "${hook_name}" "${hook?}"
105 for repo
in ${SUBMODULES_ALL?} ; do
106 refresh_submodule_hooks
"$repo"
117 if [ -n "$repo" ] ; then
118 pushd "${COREDIR?}/${repo?}" > /dev
/null
120 pushd "${COREDIR?}" > /dev
/null
123 echo "setting up push url for ${repo?}"
124 if [ "${repo?}" = "helpcontent2" ] ; then
125 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/help"
127 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/${repo?}"
136 for repo
in ${SUBMODULES_ACTIVE?} ; do
137 set_push_url
"${repo?}"
141 get_active_submodules
()
146 for repo
in ${SUBMODULES_ALL?} ; do
147 if [ -d "${repo?}"/.git
] ||
[ -f "${repo?}"/.git
] ; then
148 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
153 get_configured_submodules
()
155 SUBMODULES_CONFIGURED
=""
156 if [ -f ${BUILDDIR}/config_host.mk
] ; then
157 SUBMODULES_CONFIGURED
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_NEEDED_SUBMODULES |
sed -e "s/.*=//")
159 # if we need the configured submodule before the configuration is done. we assumed you want them all
160 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
167 if [ -f ${BUILDDIR}/config_host.mk
]; then
168 REFERENCED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_REFERENCE_SRC |
sed -e "s/.*=//")
171 if [ -f ${BUILDDIR}/config_host.mk
]; then
172 LINKED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_LINK_SRC |
sed -e "s/.*=//")
181 for module
in $SUBMODULES_CONFIGURED ; do
182 if [ ! -d "${module?}"/.git
] ; then
185 if [ -d clone
/help
/.git
] ; then
186 repo
="clone/help/.git"
190 if [ -d clone
/"${module?}"/.git
] ; then
191 repo
="clone/${module?}/.git"
195 if [ -n "$repo" ] ; then
196 cp -r "${repo?}" "${module?}/."
206 git submodule foreach git
"$@" $KEEP_GOING
212 local create_branch
="0"
216 git checkout
"$@" ||
return $?
218 if [ "$cmd" = "-f" ]; then
220 elif [ "$cmd" = "-b" ] ; then
222 elif [ "$create_branch" = "1" ] ; then
227 if [ -f .gitmodules
] ; then
228 git submodule update
--progress
229 if [ -n "$branch" ] ; then
230 git submodule foreach git checkout
-b "${branch}" HEAD ||
return $?
233 # now that is the nasty case we moved prior to submodules
234 # delete the submodules left over if any
235 for module
in $SUBMODULES_ALL ; do
236 echo "clean-up submodule $module"
239 # make sure we have the needed repo in clone
240 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
247 git
reset "$@" ||
return $?
248 if [ -f .gitmodules
] ; then
249 git submodule update
--progress ||
return $?
251 # now that is the nasty case we moved prior to submodules
252 # delete the submodules left over if any
253 for module
in $SUBMODULES_ALL ; do
254 echo "clean-up submodule $module"
257 # make sure we have the needed repo in clone
258 .
/g clone
&& .
/g
-f reset "$@"
270 for module
in $SUBMODULES_CONFIGURED ; do
271 if [ -n "$LINKED_GIT" ] ; then
272 if ! [ -d ".git/modules/${module}" ]; then
273 .
/bin
/git-new-module-workdir
"${LINKED_GIT}/${module}" "${module}"
276 configured
=$
(git config
--local --get submodule.
"${module}".url
)
277 if [ -z "$configured" ] ; then
278 git submodule init
"$module" ||
return $?
281 for module
in $SUBMODULES_CONFIGURED ; do
282 if [ -n "$REFERENCED_GIT" ] ; then
283 git submodule update
--reference "$REFERENCED_GIT/.git/modules/$module" --progress "$module" ||
return $?
285 git submodule update
--progress "$module" ||
return $?
292 # no params, no action
293 if [ "$#" -eq "0" ] ; then
297 if [ ! "$(type -p git)" ]; then
298 echo "Cannot find the git binary! Is git installed and is in PATH?"
303 get_active_submodules
304 get_configured_submodules
310 # extra params for some commands, like log
325 DO_HOOK_REFRESH
=false
327 while [ "${COMMAND:0:1}" = "-" ] ; do
338 if [ -n "${PUSH_USER}" ] ; then
339 PUSH_USER
="${PUSH_USER}@"
341 set_push_urls
"$PUSH_USER"
345 echo "option: $COMMAND not supported" 1>&2
356 do_git_cmd
"${COMMAND}" "$@"
362 do_init_modules
&& refresh_all_hooks
365 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
--progress
369 (git gc
"$@" && git submodule foreach git gc
"$@" )
373 do_git_cmd
"${COMMAND}" "$@"
376 git pull
"$@" && git submodule update
--progress && refresh_all_hooks
379 git submodule foreach git push
"$@"
380 if [ "$?" = "0" ] ; then
388 do_git_cmd
"${COMMAND}" "$@"
393 echo "./g does not support command: $COMMAND" 1>&2
400 # vi:set shiftwidth=4 expandtab: