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 local lnkfile
=".git/hooks/pre-commit"
95 pushd "${COREDIR?}" > /dev
/null
97 if [ $WINGIT -eq 1 ]; then
99 if [ -e "${lnkfile}" ] && [ -L "${lnkfile}" ] ; then
100 # if linux-links or windows-links?
101 # dos dir output windows link:
102 # 04.09.2020 10:54 <SYMLINK> pre-commit [..\..\.git-hooks\pre-commit]
103 # dos dir output linux link:
105 winlnk
=$
(cmd
/C
"DIR ${lnkfile//'/'/'\'}" 2>&1)
106 winlnk
=$
(echo "$winlnk" |
grep -icE "<SYMLINK>.*${lnkfile##*/} \[")
109 if [ $winlnk -eq 0 ]; then
110 echo "You using GIT for Windows, but the hook-links not right, change with mklink"
111 cat .git-hooks
/README
114 # There's no ".git" e.g. in a secondary worktree
115 if [ -d ".git" ]; then
116 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
117 hook
=".git/hooks/${hook_name##*/}"
118 if [ ! -e "${hook?}" ] ||
[ ! -L "${hook?}" ] ; then
120 ln -sf "${hook_name}" "${hook?}"
125 for repo
in ${SUBMODULES_ALL?} ; do
126 refresh_submodule_hooks
"$repo"
139 if [ -n "$repo" ] ; then
140 pushd "${COREDIR?}/${repo?}" > /dev
/null
142 pushd "${COREDIR?}" > /dev
/null
145 echo "setting up push url for ${repo?}"
146 if [ "${repo?}" = "helpcontent2" ] ; then
147 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/help"
149 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/${repo?}"
158 for repo
in ${SUBMODULES_ACTIVE?} ; do
159 set_push_url
"${repo?}"
163 get_active_submodules
()
168 for repo
in ${SUBMODULES_ALL?} ; do
169 if [ -d "${repo?}"/.git
] ||
[ -f "${repo?}"/.git
] ; then
170 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
175 get_configured_submodules
()
177 SUBMODULES_CONFIGURED
=""
178 if [ -f ${BUILDDIR}/config_host.mk
] ; then
179 SUBMODULES_CONFIGURED
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_NEEDED_SUBMODULES |
sed -e "s/.*=//")
181 # if we need the configured submodule before the configuration is done. we assumed you want them all
182 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
189 if [ -f ${BUILDDIR}/config_host.mk
]; then
190 REFERENCED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_REFERENCE_SRC |
sed -e "s/.*=//")
193 if [ -f ${BUILDDIR}/config_host.mk
]; then
194 LINKED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_LINK_SRC |
sed -e "s/.*=//")
203 for module
in $SUBMODULES_CONFIGURED ; do
204 if [ ! -d "${module?}"/.git
] ; then
207 if [ -d clone
/help
/.git
] ; then
208 repo
="clone/help/.git"
212 if [ -d clone
/"${module?}"/.git
] ; then
213 repo
="clone/${module?}/.git"
217 if [ -n "$repo" ] ; then
218 cp -r "${repo?}" "${module?}/."
228 git submodule foreach git
"$@" $KEEP_GOING
234 local create_branch
="0"
238 git checkout
"$@" ||
return $?
240 if [ "$cmd" = "-f" ]; then
242 elif [ "$cmd" = "-b" ] ; then
244 elif [ "$create_branch" = "1" ] ; then
249 if [ -f .gitmodules
] ; then
250 git submodule update
--progress
251 if [ -n "$branch" ] ; then
252 git submodule foreach git checkout
-b "${branch}" HEAD ||
return $?
255 # now that is the nasty case we moved prior to submodules
256 # delete the submodules left over if any
257 for module
in $SUBMODULES_ALL ; do
258 echo "clean-up submodule $module"
261 # make sure we have the needed repo in clone
262 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
269 git
reset "$@" ||
return $?
270 if [ -f .gitmodules
] ; then
271 git submodule update
--progress ||
return $?
273 # now that is the nasty case we moved prior to submodules
274 # delete the submodules left over if any
275 for module
in $SUBMODULES_ALL ; do
276 echo "clean-up submodule $module"
279 # make sure we have the needed repo in clone
280 .
/g clone
&& .
/g
-f reset "$@"
292 for module
in $SUBMODULES_CONFIGURED ; do
293 if [ -n "$LINKED_GIT" ] ; then
294 if ! [ -d ".git/modules/${module}" ]; then
295 .
/bin
/git-new-module-workdir
"${LINKED_GIT}/${module}" "${module}"
298 configured
=$
(git config
--local --get submodule.
"${module}".url
)
299 if [ -z "$configured" ] ; then
300 git submodule init
"$module" ||
return $?
303 for module
in $SUBMODULES_CONFIGURED ; do
304 if [ -n "$REFERENCED_GIT" ] ; then
305 git submodule update
--reference "$REFERENCED_GIT/.git/modules/$module" --progress "$module" ||
return $?
307 git submodule update
--progress "$module" ||
return $?
314 # no params, no action
315 if [ "$#" -eq "0" ] ; then
319 gitfile
="$(type -p git)"
321 if [ ! "${gitfile}" ]; then
322 echo "Cannot find the git binary! Is git installed and is in PATH?"
327 get_active_submodules
328 get_configured_submodules
334 # extra params for some commands, like log
349 DO_HOOK_REFRESH
=false
352 # it is 'GIT for Windows'
353 WINGIT
=$
(echo $gitfile |
grep -c cygdrive
)
354 if [ $WINGIT -eq 1 ]; then
355 gitfile
=$
(git
--version)
356 WINGIT
=$
(echo $gitfile |
grep -ic windows
)
359 while [ "${COMMAND:0:1}" = "-" ] ; do
370 if [ -n "${PUSH_USER}" ] ; then
371 PUSH_USER
="${PUSH_USER}@"
373 set_push_urls
"$PUSH_USER"
377 echo "option: $COMMAND not supported" 1>&2
388 do_git_cmd
"${COMMAND}" "$@"
394 do_init_modules
&& refresh_all_hooks
397 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
--progress
401 (git gc
"$@" && git submodule foreach git gc
"$@" )
405 do_git_cmd
"${COMMAND}" "$@"
408 git pull
"$@" && git submodule update
--progress && refresh_all_hooks
411 git submodule foreach git push
"$@"
412 if [ "$?" = "0" ] ; then
420 do_git_cmd
"${COMMAND}" "$@"
425 echo "./g does not support command: $COMMAND" 1>&2
432 # vi:set shiftwidth=4 expandtab: