When no branch is specified, fallback to the tracked branch first

This allows to work in a branch foo, which tracks e.g. master, and
using plain ./logerrit submit, have it submit to master properly.

Change-Id: I7aaff759392250a5380853cbaea0f892461c1d77
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165984
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski 2024-04-11 11:51:09 +05:00
parent 9bbecbaea3
commit b6c10f89e2

View file

@ -8,9 +8,17 @@ get_SHA_for_change() {
SHA=$(ssh "${GERRITHOST?}" gerrit query --all-approvals change:"$1" | grep ref | tail -1 | cut -d: -f2 | sed 's/^ *//') SHA=$(ssh "${GERRITHOST?}" gerrit query --all-approvals change:"$1" | grep ref | tail -1 | cut -d: -f2 | sed 's/^ *//')
} }
get_tracked_branch() {
local BRANCH=$(git symbolic-ref HEAD|sed 's|refs/heads/||')
local REMOTE=$(git config branch.$BRANCH.remote)
git rev-parse --abbrev-ref --symbolic-full-name HEAD@{upstream}|sed "s|${REMOTE}/||"
}
submit() { submit() {
BRANCH=$1 BRANCH=$1
TYPE=${2:-''} TYPE=${2:-''}
if test -z "$BRANCH"; then
BRANCH=$(get_tracked_branch)
if test -z "$BRANCH"; then if test -z "$BRANCH"; then
BRANCH=$(git symbolic-ref HEAD 2> /dev/null) BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
BRANCH="${BRANCH##refs/heads/}" BRANCH="${BRANCH##refs/heads/}"
@ -18,6 +26,7 @@ submit() {
echo "no branch specified, and could not guess the current branch" echo "no branch specified, and could not guess the current branch"
exit 1 exit 1
fi fi
fi
echo "no branch specified, guessing current branch $BRANCH" echo "no branch specified, guessing current branch $BRANCH"
fi fi
@ -179,6 +188,8 @@ case "$1" in
git branch "$BACKUPBRANCH" git branch "$BACKUPBRANCH"
echo "current state backed up as $BACKUPBRANCH" echo "current state backed up as $BACKUPBRANCH"
BRANCH=$2 BRANCH=$2
if test -z "$BRANCH"; then
BRANCH=$(get_tracked_branch)
if test -z "$BRANCH"; then if test -z "$BRANCH"; then
BRANCH=$(git symbolic-ref HEAD 2> /dev/null) BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
BRANCH="${BRANCH##refs/heads/}" BRANCH="${BRANCH##refs/heads/}"
@ -186,6 +197,7 @@ case "$1" in
echo "no branch specified, and could not guess the current branch" echo "no branch specified, and could not guess the current branch"
exit 1 exit 1
fi fi
fi
echo "no branch specified, guessing current branch $BRANCH" echo "no branch specified, guessing current branch $BRANCH"
fi fi
git reset --hard "remotes/origin/$BRANCH" git reset --hard "remotes/origin/$BRANCH"
@ -227,6 +239,8 @@ case "$1" in
CHANGEID=$3 CHANGEID=$3
BRANCH=$2 BRANCH=$2
if test -z "$BRANCH"; then
BRANCH=$(get_tracked_branch)
if test -z "$BRANCH"; then if test -z "$BRANCH"; then
BRANCH=$(git symbolic-ref HEAD 2> /dev/null) BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
BRANCH="${BRANCH##refs/heads/}" BRANCH="${BRANCH##refs/heads/}"
@ -234,6 +248,7 @@ case "$1" in
echo "no branch specified, and could not guess the current branch" echo "no branch specified, and could not guess the current branch"
exit 1 exit 1
fi fi
fi
echo "no branch specified, guessing current branch $BRANCH" echo "no branch specified, guessing current branch $BRANCH"
fi fi
BRANCH="${BRANCH##feature/}" BRANCH="${BRANCH##feature/}"