Skip to content

Commit c1fbfd8

Browse files
committed
[script_manager] fix current branch not detected
1 parent 040a83f commit c1fbfd8

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

tools/script_manager.lua

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ end
209209

210210
local function get_current_repo_branch(repo)
211211
local branch = nil
212-
local p = io.popen("cd " .. repo .. CS .. "git branch")
212+
local p = io.popen("cd " .. repo .. CS .. "git branch --all")
213213
if p then
214214
local data = p:read("*a")
215215
p:close()
@@ -857,56 +857,58 @@ local current_branch = get_current_repo_branch(LUA_DIR)
857857
local clean = is_repo_clean(repo_data)
858858
local repo = LUA_DIR
859859

860-
if sm.executables.git and clean and
861-
(current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches
862-
local branches = get_repo_branches(LUA_DIR)
863-
if current_branch ~= LUA_API_VER and current_branch ~= "master" then
864-
-- probably upgraded from an earlier api version so get back to master
865-
-- to use the latest version of script_manager to get the proper API
866-
checkout_repo_branch(repo, "master")
867-
log.msg(log.screen, "lua API version reset, please restart darktable")
868-
elseif LUA_API_VER == current_branch then
869-
-- do nothing, we are fine
870-
log.msg(log.debug, "took equal branch, doing nothing")
871-
elseif string.match(LUA_API_VER, "dev") then
872-
-- we are on a dev API version, so checkout the dev
873-
-- api version or checkout/stay on master
874-
log.msg(log.debug, "took the dev branch")
875-
local match = false
876-
for _, branch in ipairs(branches) do
877-
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
878-
if LUA_API_VER == branch then
879-
match = true
880-
log.msg(log.info, "checking out repo development branch " .. branch)
881-
checkout_repo_branch(repo, branch)
860+
if current_branch then
861+
if sm.executables.git and clean and
862+
(current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches
863+
local branches = get_repo_branches(LUA_DIR)
864+
if current_branch ~= LUA_API_VER and current_branch ~= "master" then
865+
-- probably upgraded from an earlier api version so get back to master
866+
-- to use the latest version of script_manager to get the proper API
867+
checkout_repo_branch(repo, "master")
868+
log.msg(log.screen, "lua API version reset, please restart darktable")
869+
elseif LUA_API_VER == current_branch then
870+
-- do nothing, we are fine
871+
log.msg(log.debug, "took equal branch, doing nothing")
872+
elseif string.match(LUA_API_VER, "dev") then
873+
-- we are on a dev API version, so checkout the dev
874+
-- api version or checkout/stay on master
875+
log.msg(log.debug, "took the dev branch")
876+
local match = false
877+
for _, branch in ipairs(branches) do
878+
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
879+
if LUA_API_VER == branch then
880+
match = true
881+
log.msg(log.info, "checking out repo development branch " .. branch)
882+
checkout_repo_branch(repo, branch)
883+
end
882884
end
883-
end
884-
if not match then
885-
if current_branch == "master" then
886-
log.msg(log.info, "staying on master, no dev branch yet")
887-
else
888-
log.msg(log.info, "no dev branch available, checking out master")
889-
checkout_repo_branch(repo, "master")
885+
if not match then
886+
if current_branch == "master" then
887+
log.msg(log.info, "staying on master, no dev branch yet")
888+
else
889+
log.msg(log.info, "no dev branch available, checking out master")
890+
checkout_repo_branch(repo, "master")
891+
end
890892
end
891-
end
892-
elseif #branches > 0 and LUA_API_VER > branches[#branches] then
893-
log.msg(log.info, "no newer branches, staying on master")
894-
-- stay on master
895-
else
896-
-- checkout the appropriate branch for API version if it exists
897-
log.msg(log.info, "checking out the appropriate API branch")
898-
local match = false
899-
for _, branch in ipairs(branches) do
900-
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
901-
if LUA_API_VER == branch then
902-
match = true
903-
log.msg(log.info, "checking out repo branch " .. branch)
904-
checkout_repo_branch(repo, branch)
905-
log.msg(log.screen, "you must restart darktable to use the correct version of the lua")
893+
elseif #branches > 0 and LUA_API_VER > branches[#branches] then
894+
log.msg(log.info, "no newer branches, staying on master")
895+
-- stay on master
896+
else
897+
-- checkout the appropriate branch for API version if it exists
898+
log.msg(log.info, "checking out the appropriate API branch")
899+
local match = false
900+
for _, branch in ipairs(branches) do
901+
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
902+
if LUA_API_VER == branch then
903+
match = true
904+
log.msg(log.info, "checking out repo branch " .. branch)
905+
checkout_repo_branch(repo, branch)
906+
log.msg(log.screen, "you must restart darktable to use the correct version of the lua")
907+
end
908+
end
909+
if not match then
910+
log.msg(log.warn, "no matching branch found for " .. LUA_API_VER)
906911
end
907-
end
908-
if not match then
909-
log.msg(log.warn, "no matching branch found for " .. LUA_API_VER)
910912
end
911913
end
912914
end

0 commit comments

Comments
 (0)