Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/gitlinker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ remote *gitlinker-remote*

If `remote = nil` (default), the relevant remote will be auto-detected.
If you have multiple git remotes configured and want to use a specific
one (e.g. `myfork`), do `remote = "myfork"`.
one (e.g. `myfork`), do `remote = "myfork"`. It can also be a `function`,
the return value will be used as `remote`.

add_current_line_on_normal_mode *gitlinker-add_current_line_on_normal_mode*

Expand Down
11 changes: 7 additions & 4 deletions lua/gitlinker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ local function get_buf_range_url_data(mode, user_opts)
return nil
end
mode = mode or "n"
local remote = git.get_branch_remote() or user_opts.remote
local remote = type(user_opts.remote) == "function" and user_opts.remote()
or user_opts.remote
or git.get_branch_remote()
local repo_url_data = git.get_repo_data(remote)
if not repo_url_data then
return nil
Expand Down Expand Up @@ -137,9 +139,10 @@ end
function M.get_repo_url(user_opts)
user_opts = vim.tbl_deep_extend("force", opts.get(), user_opts or {})

local repo_url_data = git.get_repo_data(
git.get_branch_remote() or user_opts.remote
)
local remote = type(user_opts.remote) == "function" and user_opts.remote()
or user_opts.remote
or git.get_branch_remote()
local repo_url_data = git.get_repo_data(remote)
if not repo_url_data then
return nil
end
Expand Down