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?}"
95 local lnkfile
=".git/hooks/pre-commit"
97 pushd "${COREDIR?}" > /dev
/null
99 # it is 'GIT for Windows'
100 wingit
=$
(git
--version |
grep -ic windows
)
101 gitbash
=$
(echo $OSTYPE |
grep -ic msys
)
103 # In the win-git-bash, do not make links, it makes only copies
104 if [ $gitbash -eq 1 ]; then
105 if [ -d ".git" ]; then
106 if [ ! -e "${lnkfile}" ] ||
[ ! -L "${lnkfile}" ] ; then
107 # here when wrong link then the file not exist
108 echo "Your hooks not right, solve this in cygwin with"
113 if [ $wingit -eq 1 ]; then
114 # There's no ".git" e.g. in a secondary worktree
115 if [ -d ".git" ]; then
117 if [ -e "${lnkfile}" ] && [ -L "${lnkfile}" ] ; then
118 # if linux-links or windows-links?
119 # dos dir output windows link:
120 # 04.09.2020 10:54 <SYMLINK> pre-commit [..\..\.git-hooks\pre-commit]
121 # dos dir output linux link:
123 winlnk
=$
(cmd
/C
"DIR ${lnkfile//'/'/'\'}" 2>&1)
124 winlnk
=$
(echo "$winlnk" |
grep -icE "<SYMLINK>.*${lnkfile##*/} \[")
127 if [ $winlnk -eq 0 ]; then
128 echo "You using GIT for Windows, but the hook-links not right, change with mklink"
129 cat .git-hooks
/README
133 # There's no ".git" e.g. in a secondary worktree
134 if [ -d ".git" ]; then
135 for hook_name
in "${COREDIR?}/.git-hooks"/* ; do
136 hook
=".git/hooks/${hook_name##*/}"
137 if [ ! -e "${hook?}" ] ||
[ ! -L "${hook?}" ] ; then
139 ln -sf "${hook_name}" "${hook?}"
144 for repo
in ${SUBMODULES_ALL?} ; do
145 refresh_submodule_hooks
"$repo"
159 if [ -n "$repo" ] ; then
160 pushd "${COREDIR?}/${repo?}" > /dev
/null
162 pushd "${COREDIR?}" > /dev
/null
165 echo "setting up push url for ${repo?}"
166 if [ "${repo?}" = "helpcontent2" ] ; then
167 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/help"
169 git config remote.origin.pushurl
"ssh://${PUSH_USER}logerrit/${repo?}"
178 for repo
in ${SUBMODULES_ACTIVE?} ; do
179 set_push_url
"${repo?}"
183 get_active_submodules
()
188 for repo
in ${SUBMODULES_ALL?} ; do
189 if [ -d "${repo?}"/.git
] ||
[ -f "${repo?}"/.git
] ; then
190 SUBMODULES_ACTIVE
="${repo?} ${SUBMODULES_ACTIVE?}"
195 get_configured_submodules
()
197 SUBMODULES_CONFIGURED
=""
198 if [ -f ${BUILDDIR}/config_host.mk
] ; then
199 SUBMODULES_CONFIGURED
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_NEEDED_SUBMODULES |
sed -e "s/.*=//")
201 # if we need the configured submodule before the configuration is done. we assumed you want them all
202 SUBMODULES_CONFIGURED
=${SUBMODULES_ALL?}
209 if [ -f ${BUILDDIR}/config_host.mk
]; then
210 REFERENCED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_REFERENCE_SRC |
sed -e "s/.*=//")
213 if [ -f ${BUILDDIR}/config_host.mk
]; then
214 LINKED_GIT
=$
(< ${BUILDDIR}/config_host.mk
grep -a GIT_LINK_SRC |
sed -e "s/.*=//")
223 for module
in $SUBMODULES_CONFIGURED ; do
224 if [ ! -d "${module?}"/.git
] ; then
227 if [ -d clone
/help
/.git
] ; then
228 repo
="clone/help/.git"
232 if [ -d clone
/"${module?}"/.git
] ; then
233 repo
="clone/${module?}/.git"
237 if [ -n "$repo" ] ; then
238 cp -r "${repo?}" "${module?}/."
248 git submodule foreach git
"$@" $KEEP_GOING
254 local create_branch
="0"
258 git checkout
"$@" ||
return $?
260 if [ "$cmd" = "-f" ]; then
262 elif [ "$cmd" = "-b" ] ; then
264 elif [ "$create_branch" = "1" ] ; then
269 if [ -f .gitmodules
] ; then
270 git submodule update
--progress
271 if [ -n "$branch" ] ; then
272 git submodule foreach git checkout
-b "${branch}" HEAD ||
return $?
275 # now that is the nasty case we moved prior to submodules
276 # delete the submodules left over if any
277 for module
in $SUBMODULES_ALL ; do
278 echo "clean-up submodule $module"
281 # make sure we have the needed repo in clone
282 .
/g clone
&& .
/g
-f checkout
"$@" ||
return $?
289 git
reset "$@" ||
return $?
290 if [ -f .gitmodules
] ; then
291 git submodule update
--progress ||
return $?
293 # now that is the nasty case we moved prior to submodules
294 # delete the submodules left over if any
295 for module
in $SUBMODULES_ALL ; do
296 echo "clean-up submodule $module"
299 # make sure we have the needed repo in clone
300 .
/g clone
&& .
/g
-f reset "$@"
312 for module
in $SUBMODULES_CONFIGURED ; do
313 if [ -n "$LINKED_GIT" ] ; then
314 if ! [ -d ".git/modules/${module}" ]; then
315 .
/bin
/git-new-module-workdir
"${LINKED_GIT}/${module}" "${module}"
318 configured
=$
(git config
--local --get submodule.
"${module}".url
)
319 if [ -z "$configured" ] ; then
320 git submodule init
"$module" ||
return $?
323 for module
in $SUBMODULES_CONFIGURED ; do
324 if [ -n "$REFERENCED_GIT" ] ; then
325 git submodule update
--reference "$REFERENCED_GIT/.git/modules/$module" --progress "$module" ||
return $?
327 git submodule update
--progress "$module" ||
return $?
334 # no params, no action
335 if [ "$#" -eq "0" ] ; then
340 if [ ! "$(type -p git)" ]; then
341 echo "Cannot find the git binary! Is git installed and is in PATH?"
346 get_active_submodules
347 get_configured_submodules
353 # extra params for some commands, like log
368 DO_HOOK_REFRESH
=false
371 while [ "${COMMAND:0:1}" = "-" ] ; do
382 if [ -n "${PUSH_USER}" ] ; then
383 PUSH_USER
="${PUSH_USER}@"
385 set_push_urls
"$PUSH_USER"
389 echo "option: $COMMAND not supported" 1>&2
400 do_git_cmd
"${COMMAND}" "$@"
406 do_init_modules
&& refresh_all_hooks
409 (git fetch
"$@" && git submodule foreach git fetch
"$@" ) && git submodule update
--progress
413 (git gc
"$@" && git submodule foreach git gc
"$@" )
417 do_git_cmd
"${COMMAND}" "$@"
420 git pull
"$@" && git submodule update
--progress && refresh_all_hooks
423 git submodule foreach git push
"$@"
424 if [ "$?" = "0" ] ; then
432 do_git_cmd
"${COMMAND}" "$@"
437 echo "./g does not support command: $COMMAND" 1>&2
444 # vi:set shiftwidth=4 expandtab: