chore: add support when HEAD is detached
This commit is contained in:
parent
ddc84cf0fd
commit
89d7ad4281
2 changed files with 15 additions and 8 deletions
|
|
@ -33,9 +33,9 @@ function M.openFile()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local current_branch_name = utils.get_current_branch()
|
local current_branch_name_or_commit_hash = utils.get_current_branch_or_commit()
|
||||||
|
|
||||||
local file_page_url = M.repo_url .. "/blob/" .. current_branch_name .. file_path
|
local file_page_url = M.repo_url .. "/blob/" .. current_branch_name_or_commit_hash .. file_path
|
||||||
|
|
||||||
local result = utils.open_url(file_page_url)
|
local result = utils.open_url(file_page_url)
|
||||||
|
|
||||||
|
|
@ -52,9 +52,9 @@ function M.openRepo()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local current_branch_name = utils.get_current_branch()
|
local current_branch_name_or_commit_hash = utils.get_current_branch_or_commit()
|
||||||
|
|
||||||
local repo_page_url = M.repo_url .. "/tree/" .. current_branch_name
|
local repo_page_url = M.repo_url .. "/tree/" .. current_branch_name_or_commit_hash
|
||||||
|
|
||||||
local result = utils.open_url(repo_page_url)
|
local result = utils.open_url(repo_page_url)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,17 @@ function M.get_defualt_branch()
|
||||||
return M.trim(branch_name)
|
return M.trim(branch_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get the active local branch
|
-- get the active local branch or commit when HEAD is detached
|
||||||
function M.get_current_branch()
|
function M.get_current_branch_or_commit()
|
||||||
local current_branch_name = vim.fn.system("git rev-parse --abbrev-ref HEAD")
|
local current_branch_name = M.trim(vim.fn.system("git rev-parse --abbrev-ref HEAD"))
|
||||||
return M.trim(current_branch_name)
|
|
||||||
|
-- HEAD is detached returing commit hash
|
||||||
|
if current_branch_name ~= "HEAD" then
|
||||||
|
return current_branch_name
|
||||||
|
end
|
||||||
|
|
||||||
|
local current_commit_hash = vim.fn.system("git rev-parse HEAD")
|
||||||
|
return M.trim(current_commit_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get the active buf relative file path form the .git
|
-- get the active buf relative file path form the .git
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue