fix(gitbrowse): use line_start and line_end directly in patterns. Closes #186

This commit is contained in:
Folke Lemaitre 2024-12-02 07:10:09 +01:00
parent 67894ee778
commit adf0433e8f
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -46,17 +46,17 @@ local defaults = {
url_patterns = { url_patterns = {
["github%.com"] = { ["github%.com"] = {
branch = "/tree/{branch}", branch = "/tree/{branch}",
file = "/blob/{branch}/{file}#L{line}", file = "/blob/{branch}/{file}#L{line_start}-L{line_end}",
commit = "/commit/{commit}", commit = "/commit/{commit}",
}, },
["gitlab%.com"] = { ["gitlab%.com"] = {
branch = "/-/tree/{branch}", branch = "/-/tree/{branch}",
file = "/-/blob/{branch}/{file}#L{line}", file = "/-/blob/{branch}/{file}#L{line_start}-L{line_end}",
commit = "/-/commit/{commit}", commit = "/-/commit/{commit}",
}, },
["bitbucket%.org"] = { ["bitbucket%.org"] = {
branch = "/src/{branch}", branch = "/src/{branch}",
file = "/src/{branch}/{file}#lines-{line}", file = "/src/{branch}/{file}#lines-{line_start}-L{line_end}",
commit = "/commits/{commit}", commit = "/commits/{commit}",
}, },
}, },
@ -125,7 +125,8 @@ function M._open(opts)
branch = opts.branch branch = opts.branch
or system({ "git", "-C", cwd, "rev-parse", "--abbrev-ref", "HEAD" }, "Failed to get current branch")[1], or system({ "git", "-C", cwd, "rev-parse", "--abbrev-ref", "HEAD" }, "Failed to get current branch")[1],
file = file and system({ "git", "-C", cwd, "ls-files", "--full-name", file }, "Failed to get git file path")[1], file = file and system({ "git", "-C", cwd, "ls-files", "--full-name", file }, "Failed to get git file path")[1],
line = nil, line_start = opts.line_start,
line_end = opts.line_end,
commit = is_commit and word, commit = is_commit and word,
} }
@ -139,10 +140,11 @@ function M._open(opts)
if line_start > line_end then if line_start > line_end then
line_start, line_end = line_end, line_start line_start, line_end = line_end, line_start
end end
fields.line = file and line_start .. "-L" .. line_end fields.line_start = line_start
fields.line_end = line_end
else else
fields.line = file fields.line_start = fields.line_start or vim.fn.line(".")
and (opts.line_start and opts.line_end and opts.line_start .. "-L" .. opts.line_end or vim.fn.line(".")) fields.line_end = fields.line_end or fields.line_start
end end
opts.what = is_commit and "commit" or opts.what == "commit" and not fields.commit and "file" or opts.what opts.what = is_commit and "commit" or opts.what == "commit" and not fields.commit and "file" or opts.what