2010-11-16 08:00:48 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Wrapper for git to handle more subdirs at the same time
|
|
|
|
#
|
2010-11-22 03:11:56 -06:00
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
if [ -n "$g_debug" ] ; then
|
|
|
|
set -x
|
2010-11-16 08:00:48 -06:00
|
|
|
fi
|
|
|
|
|
2012-11-08 16:25:37 -06:00
|
|
|
SUBMODULES_ALL="dictionaries helpcontent2 translations"
|
2010-11-16 08:00:48 -06:00
|
|
|
|
2011-08-27 23:41:18 -05:00
|
|
|
pushd $(dirname $0) > /dev/null
|
|
|
|
COREDIR=$(pwd)
|
|
|
|
popd > /dev/null
|
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
git
|
|
|
|
echo
|
|
|
|
echo "Usage: g [options] [git (checkout|clone|fetch|grep|pull|push|reset) [git options/args..]]"
|
|
|
|
echo ""
|
2012-10-16 19:43:21 -05:00
|
|
|
echo " -z restore the git hooks and do other sanity checks"
|
2012-10-01 23:48:10 -05:00
|
|
|
}
|
2012-07-10 05:57:01 -05:00
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
refresh_submodule_hooks()
|
2010-11-24 17:13:14 -06:00
|
|
|
{
|
2012-10-01 23:48:10 -05:00
|
|
|
local repo=$1
|
|
|
|
local hook
|
|
|
|
local hook_name
|
|
|
|
|
|
|
|
if [ -d ${repo?}/.git ] ; then
|
|
|
|
# use core's hook by default
|
|
|
|
for hook_name in $(ls -1 ${COREDIR?}/.git-hooks) ; do
|
|
|
|
hook="${repo?}/.git/hooks/${hook_name?}"
|
|
|
|
if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
|
|
|
|
rm -f "${hook?}"
|
|
|
|
ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
|
2011-11-03 15:52:20 -05:00
|
|
|
fi
|
2012-10-01 23:48:10 -05:00
|
|
|
done
|
|
|
|
# override if need be by the submodules' own hooks
|
|
|
|
for hook_name in $(ls -1 ${COREDIR?}/${repo?}/.git-hooks 2>/dev/null) ; do
|
|
|
|
hook="${repo?}/.git/hooks/${hook_name?}"
|
|
|
|
if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
|
|
|
|
rm -f "${hook?}"
|
|
|
|
ln -sf "${COREDIR?}/${repo?}/.git-hooks/${hook_name?}" "${hook?}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2011-08-27 23:41:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh_all_hooks()
|
|
|
|
{
|
2012-10-01 23:48:10 -05:00
|
|
|
local repo
|
|
|
|
local hook_name
|
|
|
|
local hook
|
|
|
|
|
|
|
|
pushd ${COREDIR?} > /dev/null
|
|
|
|
for hook_name in $(ls -1 ${COREDIR?}/.git-hooks) ; do
|
|
|
|
hook=".git/hooks/${hook_name?}"
|
|
|
|
if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
|
|
|
|
rm -f "${hook?}"
|
|
|
|
ln -sf "${COREDIR?}/.git-hooks/${hook_name?}" "${hook?}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for repo in ${SUBMODULES_ALL?} ; do
|
|
|
|
refresh_submodule_hooks $repo
|
|
|
|
done
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set_push_url()
|
|
|
|
{
|
|
|
|
local repo
|
|
|
|
|
|
|
|
repo="$1"
|
|
|
|
if [ -n "$repo" ] ; then
|
|
|
|
pushd "${COREDIR?}/${repo?}" > /dev/null
|
|
|
|
else
|
|
|
|
pushd "${COREDIR?}" > /dev/null
|
|
|
|
repo="core"
|
|
|
|
fi
|
|
|
|
echo "setting up push url for ${repo?}"
|
|
|
|
if [ "${repo?}" = "helpcontent2" ] ; then
|
|
|
|
git config remote.origin.pushurl "ssh://${PUSH_USER}gerrit.libreoffice.org:29418/help"
|
|
|
|
else
|
|
|
|
git config remote.origin.pushurl "ssh://${PUSH_USER}gerrit.libreoffice.org:29418/${repo?}"
|
|
|
|
fi
|
|
|
|
popd > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
set_push_urls()
|
|
|
|
{
|
|
|
|
PUSH_USER="$1"
|
|
|
|
set_push_url
|
|
|
|
for repo in ${SUBMODULES_ACTIVE?} ; do
|
|
|
|
set_push_url "${repo?}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
get_active_submodules()
|
|
|
|
{
|
|
|
|
SUBMODULES_ACTIVE=""
|
|
|
|
local repo
|
|
|
|
|
|
|
|
for repo in ${SUBMODULES_ALL?} ; do
|
|
|
|
if [ -d ${repo?}/.git ] ; then
|
|
|
|
SUBMODULES_ACTIVE="${repo?} ${SUBMODULES_ACTIVE?}"
|
|
|
|
fi
|
2010-11-24 17:13:14 -06:00
|
|
|
done
|
2011-08-27 23:41:18 -05:00
|
|
|
}
|
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
get_configured_submodules()
|
2011-08-27 23:41:18 -05:00
|
|
|
{
|
2012-10-01 23:48:10 -05:00
|
|
|
SUBMODULES_CONFIGURED=""
|
|
|
|
if [ -f "config_host.mk" ] ; then
|
|
|
|
SUBMODULES_CONFIGURED=$(cat config_host.mk | grep GIT_NEEDED_SUBMODULES | sed -e "s/.*=//")
|
|
|
|
else
|
|
|
|
# if we need the configured submoduel before the configuration is done. we assumed you want them all
|
|
|
|
SUBMODULES_CONFIGURED=${SUBMODULES_ALL?}
|
2011-03-12 16:37:38 -06:00
|
|
|
fi
|
2012-10-01 23:48:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-02 12:59:44 -05:00
|
|
|
do_shortcut_update()
|
|
|
|
{
|
|
|
|
local module
|
|
|
|
local repo
|
|
|
|
|
|
|
|
for module in $SUBMODULES_CONFIGURED ; do
|
|
|
|
if [ ! -d ${module?}/.git ] ; then
|
|
|
|
case "${module?}" in
|
2012-10-18 02:27:45 -05:00
|
|
|
helpcontent2)
|
2012-10-02 12:59:44 -05:00
|
|
|
if [ -d clone/help/.git ] ; then
|
|
|
|
repo="clone/help/.git"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -d clone/${module?}/.git ] ; then
|
|
|
|
repo="clone/${module?}/.git"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ -n "$repo" ] ; then
|
|
|
|
cp -r "${repo?}" "${module?}/."
|
|
|
|
fi
|
2012-10-02 13:29:01 -05:00
|
|
|
fi
|
2012-10-02 12:59:44 -05:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
do_git_cmd()
|
|
|
|
{
|
|
|
|
echo "cmd:$@"
|
|
|
|
git "$@"
|
|
|
|
git submodule foreach git "$@" $KEEP_GOING
|
|
|
|
}
|
|
|
|
|
|
|
|
do_checkout()
|
|
|
|
{
|
|
|
|
local cmd
|
|
|
|
local create_branch="0"
|
|
|
|
local branch
|
2012-10-02 10:32:45 -05:00
|
|
|
local module
|
2012-10-01 23:48:10 -05:00
|
|
|
|
|
|
|
git checkout "$@" || return $?
|
|
|
|
for cmd in "$@" ; do
|
|
|
|
if [ "$cmd" = "-f" ]; then
|
|
|
|
return 0
|
|
|
|
elif [ "$cmd" = "-b" ] ; then
|
|
|
|
create_branch=1
|
|
|
|
elif [ "$create_branch" = "1" ] ; then
|
|
|
|
branch="$arg"
|
2012-10-02 12:59:44 -05:00
|
|
|
create_branch=0
|
2012-10-01 23:48:10 -05:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -f .gitmodules ] ; then
|
2012-10-02 12:59:44 -05:00
|
|
|
git submodule update
|
2012-10-01 23:48:10 -05:00
|
|
|
if [ -n "$branch" ] ; then
|
2012-10-02 12:59:44 -05:00
|
|
|
git submodules foreach git checkout -b ${branch} HEAD || return $?
|
2012-10-01 23:48:10 -05:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
# now that is the nasty case we moved prior to submodules
|
2012-10-02 10:32:45 -05:00
|
|
|
# delete the submodules left over if any
|
|
|
|
for module in $SUBMODULES_ALL ; do
|
|
|
|
echo "clean-up submodule $module"
|
|
|
|
rm -fr ${module}
|
|
|
|
done
|
2012-10-01 23:48:10 -05:00
|
|
|
# make sure we have the needed repo in clone
|
|
|
|
./g clone && ./g -f checkout "$@" || return $?
|
|
|
|
fi
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
do_reset()
|
|
|
|
{
|
|
|
|
git reset "$@" || return $?
|
|
|
|
if [ -f .gitmodules ] ; then
|
|
|
|
git submodule update || return $?
|
|
|
|
else
|
|
|
|
# now that is the nasty case we moved prior to submodules
|
2012-10-02 10:32:45 -05:00
|
|
|
# delete the submodules left over if any
|
|
|
|
for module in $SUBMODULES_ALL ; do
|
|
|
|
echo "clean-up submodule $module"
|
|
|
|
rm -fr ${module}
|
|
|
|
done
|
2012-10-01 23:48:10 -05:00
|
|
|
# make sure we have the needed repo in clone
|
|
|
|
./g clone && ./g -f reset "$@"
|
|
|
|
fi
|
|
|
|
return $?;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_init_modules()
|
|
|
|
{
|
|
|
|
local module
|
|
|
|
local configured
|
2011-08-27 23:41:18 -05:00
|
|
|
|
2012-10-02 12:59:44 -05:00
|
|
|
do_shortcut_update
|
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
for module in $SUBMODULES_CONFIGURED ; do
|
|
|
|
configured=$(git config --local --get submodule.${module}.url)
|
|
|
|
if [ -z "$configured" ] ; then
|
|
|
|
git submodule init $module || return $?
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 0
|
2010-11-24 17:13:14 -06:00
|
|
|
}
|
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
|
|
|
|
# no params, no action
|
|
|
|
if [ "$#" -eq "0" ] ; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! "`type -p git`" ]; then
|
|
|
|
echo "Cannot find the git binary! Is git installed and is in PATH?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
get_active_submodules
|
|
|
|
get_configured_submodules
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-27 23:41:18 -05:00
|
|
|
|
2010-11-16 08:00:48 -06:00
|
|
|
# extra params for some commands, like log
|
|
|
|
EXTRA=
|
|
|
|
COMMAND="$1"
|
|
|
|
PAGER=
|
|
|
|
RELATIVIZE=1
|
|
|
|
PUSH_ALL=
|
2011-10-25 07:20:58 -05:00
|
|
|
PUSH_USER=
|
|
|
|
PUSH_NOTES=
|
|
|
|
LAST_WORKING=
|
|
|
|
SET_LAST_WORKING=
|
2010-11-16 08:00:48 -06:00
|
|
|
ALLOW_EMPTY=
|
2012-10-01 23:48:10 -05:00
|
|
|
KEEP_GOING=
|
2010-11-16 08:00:48 -06:00
|
|
|
REPORT_REPOS=1
|
2011-11-29 09:38:46 -06:00
|
|
|
REPORT_COMMANDS=0
|
2011-05-01 03:26:45 -05:00
|
|
|
REPORT_COMPACT=0
|
2011-08-27 23:41:18 -05:00
|
|
|
DO_HOOK_REFRESH=false
|
2010-11-16 08:00:48 -06:00
|
|
|
|
|
|
|
while [ "${COMMAND:0:1}" = "-" ] ; do
|
|
|
|
case "$COMMAND" in
|
2012-10-01 23:48:10 -05:00
|
|
|
-f )KEEP_GOING="||:"
|
2011-11-03 15:56:21 -05:00
|
|
|
;;
|
|
|
|
-z)
|
2012-10-01 23:48:10 -05:00
|
|
|
refresh_all_hooks
|
|
|
|
exit 0;
|
2011-05-01 03:26:45 -05:00
|
|
|
;;
|
2012-10-01 23:48:10 -05:00
|
|
|
--set-push-urls)
|
|
|
|
shift
|
|
|
|
PUSH_USER="$1"
|
|
|
|
if [ -n "${PUSH_USER}" ] ; then
|
|
|
|
PUSH_USER="${PUSH_USER}@"
|
|
|
|
fi
|
2012-11-23 13:58:27 -06:00
|
|
|
set_push_urls "$PUSH_USER"
|
2012-10-01 23:48:10 -05:00
|
|
|
exit 0;
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo "option: $COMMAND not supported" 1>&2
|
|
|
|
exit 1
|
2010-11-16 08:00:48 -06:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
COMMAND="$1"
|
|
|
|
done
|
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
shift
|
|
|
|
|
2010-11-16 08:00:48 -06:00
|
|
|
case "$COMMAND" in
|
2012-10-01 23:48:10 -05:00
|
|
|
branch)
|
|
|
|
do_git_cmd ${COMMAND} "$@"
|
|
|
|
;;
|
|
|
|
checkout)
|
2012-10-02 12:59:44 -05:00
|
|
|
do_checkout "$@"
|
2012-10-01 23:48:10 -05:00
|
|
|
;;
|
|
|
|
clone)
|
|
|
|
do_init_modules && git submodule update && refresh_all_hooks
|
2010-11-16 08:00:48 -06:00
|
|
|
;;
|
2012-10-01 23:48:10 -05:00
|
|
|
fetch)
|
|
|
|
(git fetch "$@" && git submodule foreach git fetch "$@" ) && git submodule update
|
|
|
|
|
|
|
|
;;
|
|
|
|
grep)
|
|
|
|
KEEP_GOING="||:"
|
|
|
|
do_git_cmd ${COMMAND} "$@"
|
|
|
|
;;
|
|
|
|
pull)
|
|
|
|
git pull "$@" && git submodule update && refresh_all_hooks
|
|
|
|
;;
|
2010-11-16 08:00:48 -06:00
|
|
|
push)
|
2012-10-01 23:48:10 -05:00
|
|
|
git submodule foreach git push "$@"
|
|
|
|
if [ "$?" = "0" ] ; then
|
|
|
|
git push "$@"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
reset)
|
|
|
|
do_reset
|
|
|
|
;;
|
2012-10-02 12:59:44 -05:00
|
|
|
tag)
|
|
|
|
do_git_cmd ${COMMAND} "$@"
|
|
|
|
;;
|
2012-10-16 19:43:21 -05:00
|
|
|
"")
|
|
|
|
;;
|
2012-10-01 23:48:10 -05:00
|
|
|
*)
|
2012-10-16 19:43:21 -05:00
|
|
|
echo "./g does not support command: $COMMAND" 1>&2
|
2012-10-01 23:48:10 -05:00
|
|
|
exit 1;
|
2010-11-16 08:00:48 -06:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2012-10-01 23:48:10 -05:00
|
|
|
exit $?
|
2011-08-27 23:41:18 -05:00
|
|
|
|
2010-11-16 08:00:48 -06:00
|
|
|
# vi:set shiftwidth=4 expandtab:
|