Skip to content

Commit

Permalink
fix: actually allow overriding remotes
Browse files Browse the repository at this point in the history
ability to override the current branch's remote, which is useful for
getting permalinks that use "origin", and not the temporary fork.

```lua
require('gitlinker').get_buf_range_url('n', {remote = "origin"})
require('gitlinker').get_buf_range_url('n', {remote = "fork"})
```
  • Loading branch information
kylo252 committed Jun 28, 2022
1 parent ff33d07 commit c9442dd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.luacheckcache
doc/tags
4 changes: 2 additions & 2 deletions lua/gitlinker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ 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 = 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 @@ -138,7 +138,7 @@ 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
user_opts.remote or git.get_branch_remote()
)
if not repo_url_data then
return nil
Expand Down
2 changes: 1 addition & 1 deletion lua/gitlinker/opts.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}

local defaults = {
remote = "origin", -- force the use of a specific remote
remote = nil, -- set it to force the use of a specific remote globally
add_current_line_on_normal_mode = true, -- if true adds the line nr in the url for normal mode
action_callback = require("gitlinker.actions").copy_to_clipboard, -- callback for what to do with the url
print_url = true, -- print the url after action
Expand Down

0 comments on commit c9442dd

Please sign in to comment.