[script_manager] fix current branch not detected

This commit is contained in:
Bill Ferguson
2021-07-05 23:24:19 -04:00
parent 040a83fb17
commit c1fbfd80d4

View File

@@ -209,7 +209,7 @@ end
local function get_current_repo_branch(repo) local function get_current_repo_branch(repo)
local branch = nil local branch = nil
local p = io.popen("cd " .. repo .. CS .. "git branch") local p = io.popen("cd " .. repo .. CS .. "git branch --all")
if p then if p then
local data = p:read("*a") local data = p:read("*a")
p:close() p:close()
@@ -857,56 +857,58 @@ local current_branch = get_current_repo_branch(LUA_DIR)
local clean = is_repo_clean(repo_data) local clean = is_repo_clean(repo_data)
local repo = LUA_DIR local repo = LUA_DIR
if sm.executables.git and clean and if current_branch then
(current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches if sm.executables.git and clean and
local branches = get_repo_branches(LUA_DIR) (current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches
if current_branch ~= LUA_API_VER and current_branch ~= "master" then local branches = get_repo_branches(LUA_DIR)
-- probably upgraded from an earlier api version so get back to master if current_branch ~= LUA_API_VER and current_branch ~= "master" then
-- to use the latest version of script_manager to get the proper API -- probably upgraded from an earlier api version so get back to master
checkout_repo_branch(repo, "master") -- to use the latest version of script_manager to get the proper API
log.msg(log.screen, "lua API version reset, please restart darktable") checkout_repo_branch(repo, "master")
elseif LUA_API_VER == current_branch then log.msg(log.screen, "lua API version reset, please restart darktable")
-- do nothing, we are fine elseif LUA_API_VER == current_branch then
log.msg(log.debug, "took equal branch, doing nothing") -- do nothing, we are fine
elseif string.match(LUA_API_VER, "dev") then log.msg(log.debug, "took equal branch, doing nothing")
-- we are on a dev API version, so checkout the dev elseif string.match(LUA_API_VER, "dev") then
-- api version or checkout/stay on master -- we are on a dev API version, so checkout the dev
log.msg(log.debug, "took the dev branch") -- api version or checkout/stay on master
local match = false log.msg(log.debug, "took the dev branch")
for _, branch in ipairs(branches) do local match = false
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) for _, branch in ipairs(branches) do
if LUA_API_VER == branch then log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
match = true if LUA_API_VER == branch then
log.msg(log.info, "checking out repo development branch " .. branch) match = true
checkout_repo_branch(repo, branch) log.msg(log.info, "checking out repo development branch " .. branch)
checkout_repo_branch(repo, branch)
end
end end
end if not match then
if not match then if current_branch == "master" then
if current_branch == "master" then log.msg(log.info, "staying on master, no dev branch yet")
log.msg(log.info, "staying on master, no dev branch yet") else
else log.msg(log.info, "no dev branch available, checking out master")
log.msg(log.info, "no dev branch available, checking out master") checkout_repo_branch(repo, "master")
checkout_repo_branch(repo, "master") end
end end
end elseif #branches > 0 and LUA_API_VER > branches[#branches] then
elseif #branches > 0 and LUA_API_VER > branches[#branches] then log.msg(log.info, "no newer branches, staying on master")
log.msg(log.info, "no newer branches, staying on master") -- stay on master
-- stay on master else
else -- checkout the appropriate branch for API version if it exists
-- checkout the appropriate branch for API version if it exists log.msg(log.info, "checking out the appropriate API branch")
log.msg(log.info, "checking out the appropriate API branch") local match = false
local match = false for _, branch in ipairs(branches) do
for _, branch in ipairs(branches) do log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) if LUA_API_VER == branch then
if LUA_API_VER == branch then match = true
match = true log.msg(log.info, "checking out repo branch " .. branch)
log.msg(log.info, "checking out repo branch " .. branch) checkout_repo_branch(repo, branch)
checkout_repo_branch(repo, branch) log.msg(log.screen, "you must restart darktable to use the correct version of the lua")
log.msg(log.screen, "you must restart darktable to use the correct version of the lua") end
end
if not match then
log.msg(log.warn, "no matching branch found for " .. LUA_API_VER)
end end
end
if not match then
log.msg(log.warn, "no matching branch found for " .. LUA_API_VER)
end end
end end
end end