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 hook
="${repo?}/.git/hooks/${hook_name##*/}"
42 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
44 ln -sf "${hook_name}" "${hook?}"
47 # override if need be by the submodules' own hooks
48 for hook_name
in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
49 hook
="${repo?}/.git/hooks/${hook_name##*/}"
50 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
52 ln -sf "${hook_name}" "${hook?}"
55 elif [ -d .git
/modules
/"${repo}"/hooks
] ; then
56 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
57 hook
=".git/modules/${repo?}/hooks/${hook_name##*/}"
58 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
60 ln -sf "${hook_name}" "${hook?}"
63 # override if need be by the submodules' own hooks
64 for hook_name
in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
65 hook
=".git/modules/${repo?}/hooks/${hook_name##*/}"
66 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
68 ln -sf "${hook_name}" "${hook?}"
81 pushd "${COREDIR?}" > /dev
/null
82 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
83 hook
=".git/hooks/${hook_name##*/}"
84 if [ ! -e "${hook?}" ] ||
[ -L "${hook?}" ] ; then
86 ln -sf "${hook_name}" "${hook?}"
90 for repo
in ${SUBMODULES_ALL?} ; do
91 refresh_submodule_hooks
"$repo"
93 # In our workflow, it's always gerrit that does the submodule updates, so
94 # better ignoring them to avoid accidentally including those changes in our
96 # 'git submodule status' can be still used to see if a submodule has such
98 for repo
in ${SUBMODULES_CONFIGURED?} ; do
99 git config submodule.
"$repo".ignore all
110 if [ -n "$repo" ] ; then
111 pushd "${COREDIR?}/${repo?}" > /dev
/null
113 pushd "${COREDIR?}" > /dev
/null
116 echo "setting up push url for ${repo?}"
117 if [ "${repo?}" = "helpcontent2" ] ; then
118 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/help"
120 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/${repo?}"
129 for repo
in ${SUBMODULES_ACTIVE?} ; do
130 set_push_url
"${repo?}"
134 get_active_submodules
()
139 for repo
in ${SUBMODULES_ALL?} ; do
140 if [ -d "${repo?}"/.git
] ||
[ -f "${repo?}"/.git
] ; then
141 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
146 get_configured_submodules
()
148 SUBMODULES_CONFIGURED
=""
149 if [ -f config_host.mk
] ; then
150 SUBMODULES_CONFIGURED
=$
(< config_host.mk
grep -a GIT_NEEDED_SUBMODULES |
sed -e "s/.*=//")
152 # if we need the configured submodule before the configuration is done. we assumed you want them all
153 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
160 if [ -f config_host.mk
]; then
161 REFERENCED_GIT
=$
(< config_host.mk
grep -a GIT_REFERENCE_SRC |
sed -e "s/.*=//")
164 if [ -f config_host.mk
]; then
165 LINKED_GIT
=$
(< config_host.mk
grep -a GIT_LINK_SRC |
sed -e "s/.*=//")
174 for module
in $SUBMODULES_CONFIGURED ; do
175 if [ ! -d "${module?}"/.git
] ; then
178 if [ -d clone
/help
/.git
] ; then
179 repo
="clone/help/.git"
183 if [ -d clone
/"${module?}"/.git
] ; then
184 repo
="clone/${module?}/.git"
188 if [ -n "$repo" ] ; then
189 cp -r "${repo?}" "${module?}/."
199 git submodule foreach git
"$@" $KEEP_GOING
205 local create_branch
="0"
209 git checkout
"$@" ||
return $?
211 if [ "$cmd" = "-f" ]; then
213 elif [ "$cmd" = "-b" ] ; then
215 elif [ "$create_branch" = "1" ] ; then
220 if [ -f .gitmodules
] ; then
222 if [ -n "$branch" ] ; then
223 git submodule foreach git checkout
-b "${branch}" HEAD ||
return $?
226 # now that is the nasty case we moved prior to submodules
227 # delete the submodules left over if any
228 for module
in $SUBMODULES_ALL ; do
229 echo "clean-up submodule $module"
232 # make sure we have the needed repo in clone
233 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
240 git
reset "$@" ||
return $?
241 if [ -f .gitmodules
] ; then
242 git submodule update ||
return $?
244 # now that is the nasty case we moved prior to submodules
245 # delete the submodules left over if any
246 for module
in $SUBMODULES_ALL ; do
247 echo "clean-up submodule $module"
250 # make sure we have the needed repo in clone
251 .
/g clone
&& .
/g
-f reset "$@"
263 for module
in $SUBMODULES_CONFIGURED ; do
264 if [ -n "$LINKED_GIT" ] ; then
265 if ! [ -d ".git/modules/${module}" ]; then
266 .
/bin
/git-new-module-workdir
"${LINKED_GIT}/${module}" "${module}"
269 configured
=$
(git config
--local --get submodule.
"${module}".url
)
270 if [ -z "$configured" ] ; then
271 git submodule init
"$module" ||
return $?
274 for module
in $SUBMODULES_CONFIGURED ; do
275 if [ -n "$REFERENCED_GIT" ] ; then
276 git submodule update
--reference "$REFERENCED_GIT/.git/modules/$module" "$module" ||
return $?
278 git submodule update
"$module" ||
return $?
285 # no params, no action
286 if [ "$#" -eq "0" ] ; then
290 if [ ! "$(type -p git)" ]; then
291 echo "Cannot find the git binary! Is git installed and is in PATH?"
296 get_active_submodules
297 get_configured_submodules
303 # extra params for some commands, like log
318 DO_HOOK_REFRESH
=false
320 while [ "${COMMAND:0:1}" = "-" ] ; do
331 if [ -n "${PUSH_USER}" ] ; then
332 PUSH_USER
="${PUSH_USER}@"
334 set_push_urls
"$PUSH_USER"
338 echo "option: $COMMAND not supported" 1>&2
349 do_git_cmd
"${COMMAND}" "$@"
355 do_init_modules
&& refresh_all_hooks
358 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
363 do_git_cmd
"${COMMAND}" "$@"
366 git pull
"$@" && git submodule update
&& refresh_all_hooks
369 git submodule foreach git push
"$@"
370 if [ "$?" = "0" ] ; then
378 do_git_cmd
"${COMMAND}" "$@"
383 echo "./g does not support command: $COMMAND" 1>&2
390 # vi:set shiftwidth=4 expandtab: