Skip to content

Commit e6b0882

Browse files
committed
config: support custom forge domains
1 parent 0f29ea4 commit e6b0882

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A git blame plugin for Neovim written in Lua
2323
- [Better Performance](#better-performance)
2424
- [Use blame commit file URLs](#use-blame-commit-file-urls)
2525
- [Set displayed commit summary length](#set-displayed-commit-summary-length)
26+
- [Remote forge domains](#remote-forge-domains)
2627
- [Commands](#commands)
2728
- [Open the commit URL in browser](#open-the-commit-url-in-browser)
2829
- [Enable/Disable git blame messages](#enabledisable-git-blame-messages)
@@ -293,6 +294,22 @@ Default: `0 (full length)`
293294
let g:gitblame_max_commit_summary_length = 50
294295
```
295296

297+
### Remote forge domains
298+
299+
A map of domain names to forge software, used to generate commit and file URLs. Currently supported software:
300+
301+
- `github`
302+
- `gitlab`
303+
- `sourcehut`
304+
- `azure`
305+
- `bitbucket`
306+
307+
```lua
308+
vim.g.gitblame_remote_domains = {
309+
"git.sr.ht" = "sourcehut"
310+
}
311+
```
312+
296313
## Commands
297314

298315
### Open the commit URL in browser

lua/gitblame/config.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ M.default_opts = {
1717
clear_event = "CursorMovedI",
1818
clipboard_register = "+",
1919
max_commit_summary_length = 0,
20+
remote_domains = {
21+
["git.sr.ht"] = "sourcehut",
22+
["dev.azure.com"] = "azure",
23+
["bitbucket.org"] = "bitbucket"
24+
}
2025
}
2126

2227
---@param opts SetupOptions?

lua/gitblame/git.lua

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ end
2727
local function get_commit_path(sha, repo_url)
2828
local domain = get_http_domain(repo_url)
2929

30-
if domain == "bitbucket.org" then
30+
local forge = vim.g.gitblame_remote_domains[domain]
31+
if forge == "bitbucket" then
3132
return "/commits/" .. sha
3233
end
3334

@@ -109,44 +110,42 @@ local function get_file_url(remote_url, branch, filepath, line1, line2)
109110
local repo_url = get_repo_url(remote_url)
110111
local domain = get_http_domain(repo_url)
111112

112-
local isSrcHut = domain == "git.sr.ht"
113-
local isBitbucket = domain == "bitbucket.org"
114-
local isAzure = domain == "dev.azure.com"
113+
local forge = vim.g.gitblame_remote_domains[domain]
115114

116115
local file_path = "/blob/" .. branch .. "/" .. filepath
117-
if isSrcHut then
116+
if forge == "sourcehut" then
118117
file_path = "/tree/" .. branch .. "/" .. filepath
119118
end
120-
if isBitbucket then
119+
if forge == "bitbucket" then
121120
file_path = "/src/" .. ref .. "/" .. filepath
122121
end
123-
if isAzure then
122+
if forge == "azure" then
124123
-- Can't use branch here since the URL wouldn't work in cases it's a commit sha
125124
file_path = "?path=%2F" .. filepath
126125
end
127126

128127
if line1 == nil then
129128
return repo_url .. file_path
130129
elseif line2 == nil or line1 == line2 then
131-
if isAzure then
130+
if forge == "azure" then
132131
return repo_url .. file_path .. "&line=" .. line1 .. "&lineEnd=" .. line1 + 1 .. "&lineStartColumn=1&lineEndColumn=1"
133132
end
134133

135-
if isBitbucket then
134+
if forge == "bitbucket" then
136135
return repo_url .. file_path .. "#lines-" .. line1
137136
end
138137

139138
return repo_url .. file_path .. "#L" .. line1
140139
else
141-
if isSrcHut then
140+
if forge == "sourcehut" then
142141
return repo_url .. file_path .. "#L" .. line1 .. "-" .. line2
143142
end
144143

145-
if isAzure then
144+
if forge == "azure" then
146145
return repo_url .. file_path .. "&line=" .. line1 .. "&lineEnd=" .. line2 + 1 .. "&lineStartColumn=1&lineEndColumn=1"
147146
end
148147

149-
if isBitbucket then
148+
if forge == "bitbucket" then
150149
return repo_url .. file_path .. "#lines-" .. line1 .. ":" .. line2
151150
end
152151

0 commit comments

Comments
 (0)