diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2023-11-29 13:49:15 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2023-11-29 13:49:15 -0500 |
commit | 34484f3ba27f8b19b04c35beadfc55868498c98e (patch) | |
tree | 81dd63c260a9be069e72137c33c25c6e595279cf /src/lpm.lua | |
parent | fb726ad715674a60dddfe770476170221fcd924b (diff) | |
download | lite-xl-plugin-manager-34484f3ba27f8b19b04c35beadfc55868498c98e.tar.gz lite-xl-plugin-manager-34484f3ba27f8b19b04c35beadfc55868498c98e.zip |
Sigh. More complicated than it should be.potentially-adding-shorthands
Diffstat (limited to 'src/lpm.lua')
-rw-r--r-- | src/lpm.lua | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/lpm.lua b/src/lpm.lua index 3195f10..a330c4b 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -353,9 +353,8 @@ function json.decode(str) end -- End JSON library. -local function is_commit_hash(hash) - return #hash == 40 and not hash:find("[^a-z0-9]") -end +local function is_commit_hash(hash) return #hash == 40 and not hash:find("[^a-f0-9]") end +local function is_probably_commit_hash(hash) return #hash > 5 and not hash:find("[^a-f0-9]") end @@ -452,10 +451,12 @@ function common.rename(src, dst) end end function common.reset(path, ref, type) + print("RESET", path, ref) if is_commit_hash(ref) then system.reset(path, ref, type) else - if not pcall(system.reset, path, "refs/tags/" .. ref, type) then system.reset(path, "refs/remotes/origin/" .. ref, type) end + --if not pcall(system.reset, path, "refs/tags/" .. ref, type) then system.reset(path, "refs/remotes/origin/" .. ref, type) end + system.reset(path, ref, type) end end function common.chdir(dir, callback) @@ -1174,7 +1175,17 @@ function Repository:fetch() if self.commit then system.fetch(temporary_path or path, write_progress_bar, self.commit) elseif self.branch then - system.fetch(temporary_path or path, write_progress_bar, "+refs/heads/" .. self.branch .. ":refs/remotes/origin/" .. self.branch) + if is_probably_commit_hash(self.branch) then + print("BRANCH", self.branch) + system.fetch(temporary_path or path, write_progress_bar, "+refs/heads/*:refs/remotes/origin/*") + self.commit = system.revparse(temporary_path or path, self.branch) + self.branch = nil + self.local_path = self.repo_path .. PATHSEP .. self.commit + path = self.local_path + else + print("OTHERWISE", self.branch) + system.fetch(temporary_path or path, write_progress_bar, "+refs/heads/" .. self.branch .. ":refs/remotes/origin/" .. self.branch) + end end common.reset(temporary_path or path, self.commit or self.branch, "hard") end @@ -1183,6 +1194,7 @@ function Repository:fetch() if temporary_path then common.mkdirp(common.dirname(path)) common.rename(temporary_path, path) + self.local_path = path end end) if not status then |