Roughly create a commit-priority implementation
This commit is contained in:
parent
871c1f837d
commit
5e742c3d7f
3 changed files with 54 additions and 9 deletions
|
|
@ -22,7 +22,18 @@ function M.setup()
|
|||
M.repo_url = string.format("http://%s/%s/%s", gh.host, gh.user_or_org, gh.reponame)
|
||||
end
|
||||
|
||||
local get_current_branch_or_commit_with_priority = function(priority)
|
||||
if (not priority) or (priority and priority == 'branch') then
|
||||
return utils.get_current_branch_or_commit()
|
||||
elseif (priority and priority == 'branch') then
|
||||
return utils.get_current_commit_or_branch()
|
||||
else
|
||||
return utils.get_current_branch_or_commit()
|
||||
end
|
||||
end
|
||||
|
||||
function M.open_file(
|
||||
priority,
|
||||
--[[optional]]
|
||||
range_start,
|
||||
--[[optional]]
|
||||
|
|
@ -43,7 +54,8 @@ function M.open_file(
|
|||
return
|
||||
end
|
||||
|
||||
local file_page_url = M.repo_url .. "/blob/" .. utils.get_current_branch_or_commit() .. file_path
|
||||
|
||||
local file_page_url = M.repo_url .. "/blob/" .. get_current_branch_or_commit_with_priority(priority) .. file_path
|
||||
|
||||
if range_start and not range_end then
|
||||
file_page_url = file_page_url .. "#L" .. range_start
|
||||
|
|
@ -58,7 +70,7 @@ function M.open_file(
|
|||
end
|
||||
end
|
||||
|
||||
function M.open_repo()
|
||||
function M.open_repo(priority)
|
||||
-- make sure to update the current directory
|
||||
M.setup()
|
||||
if M.is_no_git_origin then
|
||||
|
|
@ -66,7 +78,8 @@ function M.open_repo()
|
|||
return
|
||||
end
|
||||
|
||||
local url = M.repo_url .. "/tree/" .. utils.get_current_branch_or_commit()
|
||||
|
||||
local url = M.repo_url .. "/tree/" .. get_current_branch_or_commit_with_priority(priority)
|
||||
if not utils.open_url(url) then
|
||||
utils.notify("Could not open the built URL " .. url, vim.log.levels.ERROR)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -96,6 +96,23 @@ function M.get_current_branch_or_commit()
|
|||
return M.encode_uri_component(M.get_default_branch())
|
||||
end
|
||||
|
||||
-- Returns the current commit or branch if they are available on remote
|
||||
-- otherwise this will return the default branch of the repo
|
||||
-- (This function prioritizes commit than branch)
|
||||
function M.get_current_commit_or_branch()
|
||||
local commit_hash = get_current_commit_hash()
|
||||
if M.is_commit_upstreamed(commit_hash) then
|
||||
return commit_hash
|
||||
end
|
||||
|
||||
local current_branch = get_current_branch()
|
||||
if current_branch ~= "HEAD" and M.is_branch_upstreamed(current_branch) then
|
||||
return M.encode_uri_component(current_branch)
|
||||
end
|
||||
|
||||
return M.encode_uri_component(M.get_default_branch())
|
||||
end
|
||||
|
||||
-- get the active buf relative file path form the .git
|
||||
function M.get_current_relative_file_path()
|
||||
-- we only want the active buffer name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue