@@ -101,26 +101,31 @@ local function get_repo_url(remote_url)
101
101
end
102
102
103
103
--- @param remote_url string
104
- --- @param branch string
104
+ --- @param ref_type " commit" | " branch"
105
+ --- @param ref string
105
106
--- @param filepath string
106
107
--- @param line1 number ?
107
108
--- @param line2 number ?
108
109
--- @return string
109
- local function get_file_url (remote_url , branch , filepath , line1 , line2 )
110
+ local function get_file_url (remote_url , ref_type , ref , filepath , line1 , line2 )
110
111
local repo_url = get_repo_url (remote_url )
111
112
local domain = get_http_domain (repo_url )
112
113
113
114
local forge = vim .g .gitblame_remote_domains [domain ]
114
115
115
- local file_path = " /blob/" .. branch .. " /" .. filepath
116
+ local file_path = " /blob/" .. ref .. " /" .. filepath
116
117
if forge == " sourcehut" then
117
- file_path = " /tree/" .. branch .. " /" .. filepath
118
+ file_path = " /tree/" .. ref .. " /" .. filepath
119
+ end
120
+ if forge == " forgejo" then
121
+ file_path = " /src/" .. ref_type .. " /" .. ref .. " /" .. filepath
118
122
end
119
123
if forge == " bitbucket" then
120
124
file_path = " /src/" .. ref .. " /" .. filepath
121
125
end
122
126
if forge == " azure" then
123
- -- Can't use branch here since the URL wouldn't work in cases it's a commit sha
127
+ -- Can't use ref here if it's a commit sha
128
+ -- FIXME: add branch names to the URL
124
129
file_path = " ?path=%2F" .. filepath
125
130
end
126
131
@@ -190,13 +195,13 @@ function M.get_file_url(filepath, sha, line1, line2, callback)
190
195
if sha == nil then
191
196
get_current_branch (function (branch )
192
197
M .get_remote_url (function (remote_url )
193
- local url = get_file_url (remote_url , branch , relative_filepath , line1 , line2 )
198
+ local url = get_file_url (remote_url , " branch " , branch , relative_filepath , line1 , line2 )
194
199
callback (url )
195
200
end )
196
201
end )
197
202
else
198
203
M .get_remote_url (function (remote_url )
199
- local url = get_file_url (remote_url , sha , relative_filepath , line1 , line2 )
204
+ local url = get_file_url (remote_url , " commit " , sha , relative_filepath , line1 , line2 )
200
205
callback (url )
201
206
end )
202
207
end
0 commit comments