logerrit |   39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

New commits:
commit b6c10f89e25f43cac4eab8d596dbdba3c5e11ef2
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Apr 11 11:51:09 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Apr 11 14:08:29 2024 +0200

    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.kagan...@collabora.com>

diff --git a/logerrit b/logerrit
index 25e9943b2bbf..f9077bd6b384 100755
--- a/logerrit
+++ b/logerrit
@@ -8,15 +8,24 @@ get_SHA_for_change() {
     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() {
     BRANCH=$1
     TYPE=${2:-''}
     if test -z "$BRANCH"; then
-        BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
-        BRANCH="${BRANCH##refs/heads/}"
+        BRANCH=$(get_tracked_branch)
         if test -z "$BRANCH"; then
-            echo "no branch specified, and could not guess the current branch"
-            exit 1
+            BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
+            BRANCH="${BRANCH##refs/heads/}"
+            if test -z "$BRANCH"; then
+                echo "no branch specified, and could not guess the current 
branch"
+                exit 1
+            fi
         fi
         echo "no branch specified, guessing current branch $BRANCH"
     fi
@@ -180,11 +189,14 @@ case "$1" in
         echo "current state backed up as $BACKUPBRANCH"
         BRANCH=$2
         if test -z "$BRANCH"; then
-            BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
-            BRANCH="${BRANCH##refs/heads/}"
+            BRANCH=$(get_tracked_branch)
             if test -z "$BRANCH"; then
-                echo "no branch specified, and could not guess the current 
branch"
-                exit 1
+                BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
+                BRANCH="${BRANCH##refs/heads/}"
+                if test -z "$BRANCH"; then
+                    echo "no branch specified, and could not guess the current 
branch"
+                    exit 1
+                fi
             fi
             echo "no branch specified, guessing current branch $BRANCH"
         fi
@@ -228,11 +240,14 @@ case "$1" in
 
         BRANCH=$2
         if test -z "$BRANCH"; then
-            BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
-            BRANCH="${BRANCH##refs/heads/}"
+            BRANCH=$(get_tracked_branch)
             if test -z "$BRANCH"; then
-                echo "no branch specified, and could not guess the current 
branch"
-                exit 1
+                BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
+                BRANCH="${BRANCH##refs/heads/}"
+                if test -z "$BRANCH"; then
+                    echo "no branch specified, and could not guess the current 
branch"
+                    exit 1
+                fi
             fi
             echo "no branch specified, guessing current branch $BRANCH"
         fi
  • core.git: logerrit Moritz Duge (via logerrit)
    • core.git: logerrit Mike Kaganski (via logerrit)

Reply via email to