Commit 46fcd193 authored by Vitaly Lipatov's avatar Vitaly Lipatov

gpush: full rewrite, use mygetopts

parent ae0cc9b9
...@@ -6,112 +6,103 @@ load_mod git ...@@ -6,112 +6,103 @@ load_mod git
test -r "$1" && fatal "Do not need any files in params" test -r "$1" && fatal "Do not need any files in params"
OVERRIDEGIRARHOST= PUSHFORCE=
PUSHALL=
TAGSALL=
# If run with remote alias like girar name, use only it #############################
if is_girar_name $1 ; then Usage="Usage: $name [GIRAR/remote alias] [-f|--force] [-a|--all] [-t|--tags] [tag]"
GIRARHOST=$1 function mygetopts()
OVERRIDEGIRARHOST=$1 {
shift name=${0##*/}
fi Descr="$name - publish current project repo remote git repo"
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then phelp()
echo "gpush - publish current project repo remote git repo" {
echo "Use: gpush [GIRAR] [-f|--force] [-a|--all] [-t|--tags] [target branch]" echog "$Descr"
exit 1 echog "$Usage"
fi echog "Options:"
echog " -f - force push"
echog " -a - push all branches"
echog " -t - push all tags"
}
PUSHFORCE= while getopts :hfat opt; do
if [ "$1" = "-f" ] || [ "$1" = "--force" ] ; then case $opt in
PUSHFORCE="--force" h) phelp; exit 0;;
shift f) PUSHFORCE="--force" ;;
fi a) PUSHALL="--all" ;;
t) TAGSALL="--tags" ;;
+?) echog "$name: options should not be preceded by a '+'." 1>&2; exit 2;;
?) OPTIND=$((OPTIND-1)); break;
esac
done
PUSHALL= ## remove args that were options
if [ "$1" = "-a" ] || [ "$1" = "--all" ] ; then if [ $# -gt 0 ]; then
PUSHALL="--all" shift $((OPTIND - 1))
shift
fi fi
TAGSALL= LISTARGS=$@
if [ "$1" = "-t" ] || [ "$1" = "--tags" ] ; then
TAGSALL="--tags" }
shift
fi mygetopts $@
push_to_remote()
{
local GHOST=$1
local TEXTTAG=
local PROJECTNAME=$(pwd)/$(get_gear_name)
[ -n "$TAGSALL$PUSHALL" ] && TEXTTAG="(with all tags)"
echo
echo "** Push $TEXTBRANCH from $PROJECTNAME.git to $GHOST $TEXTTAG"
git push $PUSHALL $PUSHFORCE $GHOST $CURRENTBRANCH || return
[ -z "$TAGSALL" ] || git push --tags $GHOST $CURRENTBRANCH
}
do_push()
{
REMOTELIST="$(get_remote_git_list)" REMOTELIST="$(get_remote_git_list)"
GIRARHOST=$1
shift
# use one target if it one # use one target if it one
if is_one_girar_name "$REMOTELIST" && [ -z "$OVERRIDEGIRARHOST" ] ; then if is_one_girar_name "$REMOTELIST" && [ -z "$GIRARHOST" ] ; then
GIRARHOST="$REMOTELIST" GIRARHOST="$REMOTELIST"
OVERRIDEGIRARHOST=$GIRARHOST
fi fi
# origin by default if exists and alone
# use as project name if [ -z "$GIRARHOST" ] && [ "$(git remote | uniq)" = "origin" ] ; then
#if [ -n "$1" ] ; then GIRARHOST="origin"
# PROJECTNAME=$1 fi
# shift
#else
PROJECTNAME=$(get_gear_name)
#fi
CURRENTBRANCH=$(get_current_branch) CURRENTBRANCH=$(get_current_branch)
if [ -z "$CURRENTBRANCH" ] ; then # if set it can be tag
echo "Can't detect current branch" if [ -n "$1" ] ; then
exit 1 CURRENTBRANCH="$1"
fi shift
if [ "$1" = "origin" ]; then
REPO="$1"
shift
git push $PUSHALL $PUSHFORCE $REPO $@
git push --tags $PUSHALL $PUSHFORCE $REPO $@
exit
fi fi
if [ -z "$OVERRIDEGIRARHOST" ] && [ "$(git remote | uniq)" = "origin" ] ; then [ -n "$CURRENTBRANCH" ] || fatal "Can't detect current branch"
REPO="origin"
git push $PUSHALL $PUSHFORCE $REPO $@
git push --tags $PUSHALL $PUSHFORCE $REPO $@
exit
fi
if [ -n "$1" ] ; then
TARGETBRANCH="$1"
shift
else
TARGETBRANCH=$CURRENTBRANCH
fi
if [ "$PUSHALL" = "--all" ] ; then if [ "$PUSHALL" = "--all" ] ; then
TEXTBRANCH="all branches" TEXTBRANCH="all branches"
TARGETBRANCH= CURRENTBRANCH=
else else
TEXTBRANCH="branch $TARGETBRANCH" TEXTBRANCH="branch $CURRENTBRANCH"
if echo $TEXTBRANCH | egrep "alt|eter" ; then if echo $TEXTBRANCH | egrep "alt|eter" ; then
TEXTBRANCH="tag $TARGETBRANCH" TEXTBRANCH="tag $CURRENTBRANCH"
fi fi
fi fi
push_to_remote()
{
local GHOST=$1
local TEXTTAG=
[ -n "$TAGSALL$PUSHALL" ] && TEXTTAG="(with all tags)"
# FIXME: почему тут прибито packages, а мы не используем remote alias, если он есть?
# Видимо, стоит только через alias, он же всё равно создаётся, и мы всё равно его используем, чтобы определить, куда публиковать
echo
echo "** Push $TEXTBRANCH from $PROJECTNAME.git to $GHOST $TEXTTAG"
# FIXME: push with one command
if [ -n "$PUSHALL" ] ; then
git push $PUSHALL $PUSHFORCE $GHOST || return
[ -z "$TAGSALL" ] || git push --tags $GHOST
else
git push $PUSHALL $PUSHFORCE $GHOST $TARGETBRANCH || return
[ -z "$TAGSALL" ] || git push --tags $GHOST $TARGETBRANCH
fi
}
# if remote list is empty, do ginit # if remote list is empty, do ginit
...@@ -122,3 +113,6 @@ LISTGIRARHOST="$GIRARHOST $(do_exclude_list "$GIRARHOST" "$REMOTELIST")" ...@@ -122,3 +113,6 @@ LISTGIRARHOST="$GIRARHOST $(do_exclude_list "$GIRARHOST" "$REMOTELIST")"
for i in $LISTGIRARHOST ; do for i in $LISTGIRARHOST ; do
push_to_remote $i push_to_remote $i
done done
}
do_push $LISTARGS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment