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"
38 # if it doesn't exist or is neither a symlink nor sharing the same inode (hardlink)
39 if [ ! -e "${hook?}" ] || [ ! \( -L "${hook?}" -o "${hook_name}" -ef "${hook?}" \
) ] ; then
41 ln -f $lnarg "${hook_name}" "${hook?}"
45 refresh_submodule_hooks
()
52 if [ -d "${repo?}"/.git
] ; then
53 # use core's hook by default
54 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
55 if [ ! -e "${hook_name}" ] ; then
58 hook
="${repo?}/.git/hooks/${hook_name##*/}"
59 refresh_create_link
"${hook_name}" "${hook?}" "$lnarg"
61 # override if need be by the submodules' own hooks
62 for hook_name
in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
63 if [ ! -e "${hook_name}" ] ; then
66 hook
="${repo?}/.git/hooks/${hook_name##*/}"
67 refresh_create_link
"${hook_name}" "${hook?}" "$lnarg"
69 elif [ -d .git
/modules
/"${repo}"/hooks
] ; then
70 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
71 if [ ! -e "${hook_name}" ] ; then
74 hook
=".git/modules/${repo?}/hooks/${hook_name##*/}"
75 refresh_create_link
"${hook_name}" "${hook?}" "$lnarg"
77 # override if need be by the submodules' own hooks
78 for hook_name
in "${COREDIR?}/${repo?}/.git-hooks"/* ; do
79 if [ ! -e "${hook_name}" ] ; then
82 hook
=".git/modules/${repo?}/hooks/${hook_name##*/}"
83 refresh_create_link
"${hook_name}" "${hook?}" "$lnarg"
97 pushd "${COREDIR?}" > /dev
/null
99 # it is 'GIT for Windows'
100 gitbash
=$
(echo $OSTYPE |
grep -ic msys
)
102 # git-bash/MSYS doesn't create symlinks by default, and "real" symlinks are restricted to
103 # Admin-mode or when devmode is activated, junction points as fallback would work for bash/
104 # regular use but not when git tries to spawn them, similar for plain windows shortcuts (worse
105 # because running the hooks will fail silently/they'd be inactive)
106 # ln -s without setting MSYS to contain winsymlinks:{lnk,native,nativestrict,sys} to force one
107 # of the other modes described above will do plain copies.
108 # So in case of git-bash use hardlinks since those work just fine, everywhere else use symlinks
109 if [ $gitbash -ne 1 ]; then
112 # There's no ".git" e.g. in a secondary worktree
113 if [ -d ".git" ]; then
114 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
115 hook
=".git/hooks/${hook_name##*/}"
116 refresh_create_link
"${hook_name}" "${hook?}" "$lnarg"
120 for repo
in ${SUBMODULES_ALL?} ; do
121 refresh_submodule_hooks
"$repo" "$lnarg"
133 if [ -n "$repo" ] ; then
134 pushd "${COREDIR?}/${repo?}" > /dev
/null
136 pushd "${COREDIR?}" > /dev
/null
139 echo "setting up push url for ${repo?}"
140 if [ "${repo?}" = "helpcontent2" ] ; then
141 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/help"
143 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/${repo?}"
152 for repo
in ${SUBMODULES_ACTIVE?} ; do
153 set_push_url
"${repo?}"
157 get_active_submodules
()
162 for repo
in ${SUBMODULES_ALL?} ; do
163 if [ -d "${repo?}"/.git
] ||
[ -f "${repo?}"/.git
] ; then
164 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
169 get_configured_submodules
()
171 SUBMODULES_CONFIGURED
=""
172 if [ -f ${BUILDDIR}/config_host.mk
] ; then
173 SUBMODULES_CONFIGURED
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_NEEDED_SUBMODULES |
sed -e "s/.*=//")
175 # if we need the configured submodule before the configuration is done. we assumed you want them all
176 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
183 if [ -f ${BUILDDIR}/config_host.mk
]; then
184 REFERENCED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_REFERENCE_SRC |
sed -e "s/.*=//")
187 if [ -f ${BUILDDIR}/config_host.mk
]; then
188 LINKED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_LINK_SRC |
sed -e "s/.*=//")
197 for module
in $SUBMODULES_CONFIGURED ; do
198 if [ ! -d "${module?}"/.git
] ; then
201 if [ -d clone
/help
/.git
] ; then
202 repo
="clone/help/.git"
206 if [ -d clone
/"${module?}"/.git
] ; then
207 repo
="clone/${module?}/.git"
211 if [ -n "$repo" ] ; then
212 cp -r "${repo?}" "${module?}/."
222 git submodule foreach git
"$@" $KEEP_GOING
228 local create_branch
="0"
232 git checkout
"$@" ||
return $?
234 if [ "$cmd" = "-f" ]; then
236 elif [ "$cmd" = "-b" ] ; then
238 elif [ "$create_branch" = "1" ] ; then
243 if [ -f .gitmodules
] ; then
244 git submodule update
--progress
245 if [ -n "$branch" ] ; then
246 git submodule foreach git checkout
-b "${branch}" HEAD ||
return $?
249 # now that is the nasty case we moved prior to submodules
250 # delete the submodules left over if any
251 for module
in $SUBMODULES_ALL ; do
252 echo "clean-up submodule $module"
255 # make sure we have the needed repo in clone
256 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
263 git
reset "$@" ||
return $?
264 if [ -f .gitmodules
] ; then
265 git submodule update
--progress ||
return $?
267 # now that is the nasty case we moved prior to submodules
268 # delete the submodules left over if any
269 for module
in $SUBMODULES_ALL ; do
270 echo "clean-up submodule $module"
273 # make sure we have the needed repo in clone
274 .
/g clone
&& .
/g
-f reset "$@"
286 for module
in $SUBMODULES_CONFIGURED ; do
287 if [ -n "$LINKED_GIT" ] ; then
288 if ! [ -d ".git/modules/${module}" ]; then
289 .
/bin
/git-new-module-workdir
"${LINKED_GIT}/${module}" "${module}"
292 configured
=$
(git config
--local --get submodule.
"${module}".url
)
293 if [ -z "$configured" ] ; then
294 git submodule init
"$module" ||
return $?
297 for module
in $SUBMODULES_CONFIGURED ; do
298 if [ -n "$REFERENCED_GIT" ] ; then
299 git submodule update
--reference "$REFERENCED_GIT/.git/modules/$module" --progress "$module" ||
return $?
301 git submodule update
--progress "$module" ||
return $?
308 # no params, no action
309 if [ "$#" -eq "0" ] ; then
314 if [ ! "$(type -p git)" ]; then
315 echo "Cannot find the git binary! Is git installed and is in PATH?"
320 get_active_submodules
321 get_configured_submodules
327 # extra params for some commands, like log
342 DO_HOOK_REFRESH
=false
345 while [ "${COMMAND:0:1}" = "-" ] ; do
356 if [ -n "${PUSH_USER}" ] ; then
357 PUSH_USER
="${PUSH_USER}@"
359 set_push_urls
"$PUSH_USER"
363 echo "option: $COMMAND not supported" 1>&2
374 do_git_cmd
"${COMMAND}" "$@"
380 do_init_modules
&& refresh_all_hooks
383 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
--progress
387 (git gc
"$@" && git submodule foreach git gc
"$@" )
391 do_git_cmd
"${COMMAND}" "$@"
394 git pull
"$@" && git submodule update
--progress && refresh_all_hooks
397 git submodule foreach git push
"$@"
398 if [ "$?" = "0" ] ; then
406 do_git_cmd
"${COMMAND}" "$@"
411 echo "./g does not support command: $COMMAND" 1>&2
418 # vi:set shiftwidth=4 expandtab: