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"
102 if [ -n "$repo" ] ; then
103 pushd "${COREDIR?}/${repo?}" > /dev
/null
105 pushd "${COREDIR?}" > /dev
/null
108 echo "setting up push url for ${repo?}"
109 if [ "${repo?}" = "helpcontent2" ] ; then
110 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/help"
112 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/${repo?}"
121 for repo
in ${SUBMODULES_ACTIVE?} ; do
122 set_push_url
"${repo?}"
126 get_active_submodules
()
131 for repo
in ${SUBMODULES_ALL?} ; do
132 if [ -d "${repo?}"/.git
] ||
[ -f "${repo?}"/.git
] ; then
133 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
138 get_configured_submodules
()
140 SUBMODULES_CONFIGURED
=""
141 if [ -f config_host.mk
] ; then
142 SUBMODULES_CONFIGURED
=$
(< config_host.mk
grep -a GIT_NEEDED_SUBMODULES |
sed -e "s/.*=//")
144 # if we need the configured submodule before the configuration is done. we assumed you want them all
145 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
152 if [ -f config_host.mk
]; then
153 REFERENCED_GIT
=$
(< config_host.mk
grep -a GIT_REFERENCE_SRC |
sed -e "s/.*=//")
156 if [ -f config_host.mk
]; then
157 LINKED_GIT
=$
(< config_host.mk
grep -a GIT_LINK_SRC |
sed -e "s/.*=//")
166 for module
in $SUBMODULES_CONFIGURED ; do
167 if [ ! -d "${module?}"/.git
] ; then
170 if [ -d clone
/help
/.git
] ; then
171 repo
="clone/help/.git"
175 if [ -d clone
/"${module?}"/.git
] ; then
176 repo
="clone/${module?}/.git"
180 if [ -n "$repo" ] ; then
181 cp -r "${repo?}" "${module?}/."
191 git submodule foreach git
"$@" $KEEP_GOING
197 local create_branch
="0"
201 git checkout
"$@" ||
return $?
203 if [ "$cmd" = "-f" ]; then
205 elif [ "$cmd" = "-b" ] ; then
207 elif [ "$create_branch" = "1" ] ; then
212 if [ -f .gitmodules
] ; then
214 if [ -n "$branch" ] ; then
215 git submodule foreach git checkout
-b "${branch}" HEAD ||
return $?
218 # now that is the nasty case we moved prior to submodules
219 # delete the submodules left over if any
220 for module
in $SUBMODULES_ALL ; do
221 echo "clean-up submodule $module"
224 # make sure we have the needed repo in clone
225 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
232 git
reset "$@" ||
return $?
233 if [ -f .gitmodules
] ; then
234 git submodule update ||
return $?
236 # now that is the nasty case we moved prior to submodules
237 # delete the submodules left over if any
238 for module
in $SUBMODULES_ALL ; do
239 echo "clean-up submodule $module"
242 # make sure we have the needed repo in clone
243 .
/g clone
&& .
/g
-f reset "$@"
255 for module
in $SUBMODULES_CONFIGURED ; do
256 if [ -n "$LINKED_GIT" ] ; then
257 if ! [ -d ".git/modules/${module}" ]; then
258 .
/bin
/git-new-module-workdir
"${LINKED_GIT}/${module}" "${module}"
261 configured
=$
(git config
--local --get submodule.
"${module}".url
)
262 if [ -z "$configured" ] ; then
263 git submodule init
"$module" ||
return $?
266 for module
in $SUBMODULES_CONFIGURED ; do
267 if [ -n "$REFERENCED_GIT" ] ; then
268 git submodule update
--reference "$REFERENCED_GIT/.git/modules/$module" "$module" ||
return $?
270 git submodule update
"$module" ||
return $?
277 # no params, no action
278 if [ "$#" -eq "0" ] ; then
282 if [ ! "$(type -p git)" ]; then
283 echo "Cannot find the git binary! Is git installed and is in PATH?"
288 get_active_submodules
289 get_configured_submodules
295 # extra params for some commands, like log
310 DO_HOOK_REFRESH
=false
312 while [ "${COMMAND:0:1}" = "-" ] ; do
323 if [ -n "${PUSH_USER}" ] ; then
324 PUSH_USER
="${PUSH_USER}@"
326 set_push_urls
"$PUSH_USER"
330 echo "option: $COMMAND not supported" 1>&2
341 do_git_cmd
"${COMMAND}" "$@"
347 do_init_modules
&& refresh_all_hooks
350 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
355 do_git_cmd
"${COMMAND}" "$@"
358 git pull
"$@" && git submodule update
&& refresh_all_hooks
361 git submodule foreach git push
"$@"
362 if [ "$?" = "0" ] ; then
370 do_git_cmd
"${COMMAND}" "$@"
375 echo "./g does not support command: $COMMAND" 1>&2
382 # vi:set shiftwidth=4 expandtab: