chore: add support for diffrent branches
This commit is contained in:
parent
94e9af95c1
commit
dba902f5cc
2 changed files with 33 additions and 2 deletions
|
|
@ -35,6 +35,18 @@ function M.openRepo()
|
||||||
end
|
end
|
||||||
|
|
||||||
local repo_url = M.gh_url .. M.username .. "/" .. M.reponame
|
local repo_url = M.gh_url .. M.username .. "/" .. M.reponame
|
||||||
|
|
||||||
|
-- check if not the default branch add it to the url
|
||||||
|
local current_branch_name = utils.get_current_branch()
|
||||||
|
local default_branch_name = utils.get_defualt_branch()
|
||||||
|
|
||||||
|
print(current_branch_name)
|
||||||
|
print(default_branch_name)
|
||||||
|
|
||||||
|
if current_branch_name ~= default_branch_name then
|
||||||
|
repo_url = repo_url .. "/tree/" .. current_branch_name
|
||||||
|
end
|
||||||
|
|
||||||
local result = utils.open_url(repo_url)
|
local result = utils.open_url(repo_url)
|
||||||
|
|
||||||
if result then
|
if result then
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,12 @@ function M.split(string, char)
|
||||||
return array
|
return array
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- trim extra spaces and newlines
|
||||||
|
-- useful when working with git commands returned values
|
||||||
|
function M.trim(string)
|
||||||
|
return (string:gsub("^%s*(.-)%s*$", "%1"))
|
||||||
|
end
|
||||||
|
|
||||||
-- returns the username and the reponame form the origin url in a table
|
-- returns the username and the reponame form the origin url in a table
|
||||||
function M.get_username_reponame(url)
|
function M.get_username_reponame(url)
|
||||||
-- ssh has an @ in the url
|
-- ssh has an @ in the url
|
||||||
|
|
@ -18,7 +24,7 @@ function M.get_username_reponame(url)
|
||||||
local splitted_username_and_reponame = M.split(splitted_user_repo, "/")
|
local splitted_username_and_reponame = M.split(splitted_user_repo, "/")
|
||||||
local username_and_reponame = {
|
local username_and_reponame = {
|
||||||
username = splitted_username_and_reponame[1],
|
username = splitted_username_and_reponame[1],
|
||||||
reponame = string.gsub(splitted_username_and_reponame[2], ".git", ""),
|
reponame = M.trim(string.gsub(splitted_username_and_reponame[2], ".git", "")),
|
||||||
}
|
}
|
||||||
|
|
||||||
return username_and_reponame
|
return username_and_reponame
|
||||||
|
|
@ -26,13 +32,26 @@ function M.get_username_reponame(url)
|
||||||
local splitted_username_and_reponame = M.split(url, "/")
|
local splitted_username_and_reponame = M.split(url, "/")
|
||||||
local username_and_reponame = {
|
local username_and_reponame = {
|
||||||
username = splitted_username_and_reponame[3],
|
username = splitted_username_and_reponame[3],
|
||||||
reponame = string.gsub(splitted_username_and_reponame[4], ".git", ""),
|
reponame = M.trim(string.gsub(splitted_username_and_reponame[4], ".git", "")),
|
||||||
}
|
}
|
||||||
|
|
||||||
return username_and_reponame
|
return username_and_reponame
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_defualt_branch()
|
||||||
|
-- will return origin/[branch_name]
|
||||||
|
local branch_with_origin = vim.fn.system("git rev-parse --abbrev-ref origin/HEAD")
|
||||||
|
local branch_name = M.split(branch_with_origin, "/")[2]
|
||||||
|
|
||||||
|
return M.trim(branch_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_current_branch()
|
||||||
|
local current_branch_name = vim.fn.system("git rev-parse --abbrev-ref HEAD")
|
||||||
|
return M.trim(current_branch_name)
|
||||||
|
end
|
||||||
|
|
||||||
-- opens a url in the correct OS
|
-- opens a url in the correct OS
|
||||||
function M.open_url(url)
|
function M.open_url(url)
|
||||||
local os = M.get_os()
|
local os = M.get_os()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue