git: 1c6170d77122 - main - git-arc: Add stage -n to not change the branch

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 08 Apr 2025 10:49:03 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=1c6170d7712265beecb318309ec5afaddbcf350e

commit 1c6170d7712265beecb318309ec5afaddbcf350e
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2025-01-13 05:34:24 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2025-04-08 10:31:43 +0000

    git-arc: Add stage -n to not change the branch
    
    This can be useful when staging to a non-main branch
---
 tools/tools/git/git-arc.sh | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/tools/git/git-arc.sh b/tools/tools/git/git-arc.sh
index b49721159799..7d2387565b9a 100644
--- a/tools/tools/git/git-arc.sh
+++ b/tools/tools/git/git-arc.sh
@@ -654,11 +654,15 @@ gitarc__stage()
     local author branch commit commits diff reviewers title tmp
 
     branch=main
-    while getopts b: o; do
+    change_branch=yes
+    while getopts b:n o; do
         case "$o" in
         b)
             branch="$OPTARG"
             ;;
+        n)
+            change_branch=no
+            ;;
         *)
             err_usage
             ;;
@@ -668,10 +672,12 @@ gitarc__stage()
 
     commits=$(build_commit_list "$@")
 
-    if [ "$branch" = "main" ]; then
-        git checkout -q main
-    else
-        git checkout -q -b "${branch}" main
+    if [ "$change_branch" = "yes" ]; then
+        if [ "$branch" = "main" ]; then
+            git checkout -q main
+        else
+            git checkout -q -b "${branch}" main
+        fi
     fi
 
     tmp=$(xmktemp)