Skip to content

Commit e57d72a

Browse files
committed
mfc-candidates: Improve branch detection and repository handling
- Use git to detect the latest stable branch rather than hardcoding it. - Handle the case where the script is run outside a src or ports repository. - Fix a pattern to match .git instead of *git. Reviewed by: andrew, releng (emaste) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52681
1 parent 54b24b9 commit e57d72a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/tools/git/mfc-candidates.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,18 @@ local function main()
129129
local author = os.getenv("USER") or ""
130130
local dirspec = nil
131131

132-
local url = exec_command("git remote get-url freebsd")
133-
local freebsd_repo = string.match(url, "[^/]+$")
134-
freebsd_repo = string.gsub(freebsd_repo, ".git$", "")
132+
local url = exec_command("git remote get-url freebsd 2>/dev/null")
133+
local freebsd_repo
134+
if url and url ~= "" then
135+
freebsd_repo = string.match(url, "[^/]+$")
136+
freebsd_repo = string.gsub(freebsd_repo, "%.git$", "")
137+
end
135138
if freebsd_repo == "ports" or freebsd_repo == "freebsd-ports" then
136139
local year = os.date("%Y")
137140
local month = os.date("%m")
138141
local qtr = math.ceil(month / 3)
139142
to_branch = "freebsd/" .. year .. "Q" .. qtr
140143
elseif freebsd_repo == "src" or freebsd_repo == "freebsd-src" then
141-
to_branch = "freebsd/stable/14"
142144
-- If pwd is a stable or release branch tree, default to it.
143145
local cur_branch = exec_command("git symbolic-ref --short HEAD")
144146
if string.match(cur_branch, "^stable/") then
@@ -147,6 +149,11 @@ local function main()
147149
to_branch = cur_branch
148150
local major = string.match(cur_branch, "%d+")
149151
from_branch = "freebsd/stable/" .. major
152+
else
153+
-- Use latest stable branch.
154+
to_branch = exec_command("git for-each-ref --sort=-v:refname " ..
155+
"--format='%(refname:lstrip=2)' " ..
156+
"refs/remotes/freebsd/stable/* --count=1")
150157
end
151158
else
152159
print("pwd is not under a ports or src repository.")

0 commit comments

Comments
 (0)