## Description
The previous logic didn't check for `fields.commit` when checking
whether to switch to `branch` or `repo`, thus `opts.what = "commit"` was
always being overwritten.
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
## Related Issue(s)
None
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
The extra % before - is needed in Lua. Without this rule, `<leader>gB`
would just open empty browser.
## Description
Support repo url in format:
`org-123456@github.com:repo-group/repo-name.git`
## Description
`Snacks.gitbrowse({ what = "permalink" })` got following error when
`vim.fn.getcwd()` is not a git repository or not the git repository of
current file:
```
E5108: Error executing lua ...cal/share/nvim/lazy/snacks.nvim/lua/snacks/gitbrowse.lua:137: ...cal/share/nvim/lazy/snacks.nvim/lua/snacks/gitbrowse.lua:117: __ignore__
stack traceback:
[C]: in function 'error'
...cal/share/nvim/lazy/snacks.nvim/lua/snacks/gitbrowse.lua:137: in function 'gitbrowse'
[string ":lua"]:1: in main chunk
Failed to get latest commit of file
fatal: not a git repository (or any of the parent directories): .git
```
## Related Issue(s)
- Fixes#320
- Related #438
## Screenshots
None.
## Description
Add new variant of `what` to link to files permanently.
## Related Issue(s)
Fixes#320
---------
Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
## Description
Allow the user to be able to define custom branch with
`Snacks.gitbrowse`. I also added `start_line` and `end_line` (default to
`nil`), because from my testing when using a keymap such as the one in
[my comment in the related
issue](https://github.com/folke/snacks.nvim/issues/170#issuecomment-2508476110)
or this one which I came up later while implementing this
```lua
vim.keymap.set({ "n", "x" }, "<leader>gY", function()
local function system(cmd, err)
local proc = vim.fn.system(cmd)
if vim.v.shell_error ~= 0 then
Snacks.notify.error({ err, proc }, { title = "Git Browse" })
error(err)
end
return vim.split(vim.trim(proc), "\n")
end
local branches = {}
local start_line, end_line
if vim.fn.mode() == "v" or vim.fn.mode() == "V" then
start_line = vim.fn.line("v")
end_line = vim.fn.line(".")
if start_line > end_line then
start_line, end_line = end_line, start_line
end
end
for _, branch in ipairs(system({ "git", "branch" }, "Failed to get git branches")) do
branch = branch:match("%s*[%*]?%s*(%S+)")
table.insert(branches, branch)
end
vim.ui.select(branches, {
prompt = "Select branch",
}, function(choice)
if choice then
Snacks.gitbrowse({ start_line = start_line or nil, end_line = end_line or nil, branch = choice })
end
end)
end, { desc = "Git Browse ()" })
```
Then the visual lines would not work. My guess is that in the first case
the command line prompt and in the second case the `vim.ui.select`
before calling `Snacks.gitbrowse` break the Visual mode state and any
visual selection is not propagated to `Snacks.gitbrowse` to be properly
evaluated by the internal code for visual lines selection, which works
just fine when you just call directly `Snacks.gitbrowse()` via a
function in a keymap (which I assume doesn't break Visual mode state).
That's why I had to implement the visual selection again in the keymap
as well and needed the extra parameters to pass the newly evaluated
values.
Please do correct me if I'm somehow wrong in my logical deduction (which
is based mostly on observation and guessing) and maybe `start_line` and
`end_line` are not needed. Except if the user passes the option directly
in the keymap, but then he would have to create multiple keymaps for
different branches, which in my personal opinion defeats the purpose of
this feature.
In both cases of the keymaps I mentioned the user can dynamically either
type or choose the branch available to him. But maybe I'm missing
something in both the keymaps implementations that I came up with.
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
## Related Issue(s)
Closes#170.
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
---------
Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
## Description
`gitbrowse` opens commit when word under cursor is valid commit hash.
Please check the Lua pattern for the commit hash in the validation
function I used as I'm not confident as to if it covers all the cases. I
only tested with `diffview` file history and `gitsigns` blame buffer as
I don't use other tools.
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
## Related Issue(s)
Closes#138.
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
## Description
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
This enables users to open commits hosted on bitbucket repositories.
## Related Issue(s)
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
https://github.com/folke/snacks.nvim/issues/162https://github.com/folke/snacks.nvim/issues/138
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
Co-authored-by: Krishna Balasubramanian <krishna@foxbots.com>
## Description
`gitbrowse` takes into account line range when in Visual mode.
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
## Related Issue(s)
Closes#88.
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>