git: 4b3bf909005a - main - mfc-candidates.sh: Set default target branch for ports

From: Joseph Mingrone <jrm_at_FreeBSD.org>
Date: Wed, 04 May 2022 19:48:20 UTC
The branch main has been updated by jrm (ports committer):

URL: https://cgit.FreeBSD.org/src/commit/?id=4b3bf909005a8b89d55fb27b8dde6128dda61751

commit 4b3bf909005a8b89d55fb27b8dde6128dda61751
Author:     Joseph Mingrone <jrm@FreeBSD.org>
AuthorDate: 2022-05-04 19:43:20 +0000
Commit:     Joseph Mingrone <jrm@FreeBSD.org>
CommitDate: 2022-05-04 19:43:20 +0000

    mfc-candidates.sh: Set default target branch for ports
    
    Approved by:    emaste, jhb
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D35096
---
 tools/tools/git/mfc-candidates.sh | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/tools/tools/git/mfc-candidates.sh b/tools/tools/git/mfc-candidates.sh
index 623edc7174a1..45f3b645e4ba 100644
--- a/tools/tools/git/mfc-candidates.sh
+++ b/tools/tools/git/mfc-candidates.sh
@@ -30,21 +30,34 @@
 # SUCH DAMAGE.
 
 from_branch=freebsd/main
-to_branch=freebsd/stable/13
 author="${USER}"
 
-# If pwd is a stable or release branch tree, default to it.
-cur_branch=$(git symbolic-ref --short HEAD 2>/dev/null)
-case $cur_branch in
-stable/*)
-	to_branch=$cur_branch
-	;;
-releng/*)
-	to_branch=$cur_branch
-	major=${cur_branch#releng/}
-	major=${major%.*}
-	from_branch=freebsd/stable/$major
-esac
+# Get the FreeBSD repository
+repo=$(basename "$(git remote get-url freebsd 2>/dev/null)" 2>/dev/null)
+
+if [ "${repo}" = "ports.git" ]; then
+	year=$(date '+%Y')
+	month=$(date '+%m')
+	qtr=$(((month-1) / 3 + 1))
+	to_branch="freebsd/${year}Q${qtr}"
+elif [ "${repo}" = "src.git" ]; then
+	to_branch=freebsd/stable/13
+	# If pwd is a stable or release branch tree, default to it.
+	cur_branch=$(git symbolic-ref --short HEAD 2>/dev/null)
+	case $cur_branch in
+	stable/*)
+		to_branch=$cur_branch
+		;;
+	releng/*)
+		to_branch=$cur_branch
+		major=${cur_branch#releng/}
+		major=${major%.*}
+		from_branch=freebsd/stable/$major
+	esac
+else
+	echo "pwd is not under a ports or src repository."
+	exit 0
+fi
 
 params()
 {