@@ -101,26 +101,31 @@ local function get_repo_url(remote_url)
101101end
102102
103103--- @param remote_url string
104- --- @param branch string
104+ --- @param ref_type " commit" | " branch"
105+ --- @param ref string
105106--- @param filepath string
106107--- @param line1 number ?
107108--- @param line2 number ?
108109--- @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 )
110111 local repo_url = get_repo_url (remote_url )
111112 local domain = get_http_domain (repo_url )
112113
113114 local forge = vim .g .gitblame_remote_domains [domain ]
114115
115- local file_path = " /blob/" .. branch .. " /" .. filepath
116+ local file_path = " /blob/" .. ref .. " /" .. filepath
116117 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
118122 end
119123 if forge == " bitbucket" then
120124 file_path = " /src/" .. ref .. " /" .. filepath
121125 end
122126 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
124129 file_path = " ?path=%2F" .. filepath
125130 end
126131
@@ -190,13 +195,13 @@ function M.get_file_url(filepath, sha, line1, line2, callback)
190195 if sha == nil then
191196 get_current_branch (function (branch )
192197 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 )
194199 callback (url )
195200 end )
196201 end )
197202 else
198203 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 )
200205 callback (url )
201206 end )
202207 end
0 commit comments