Commit graph

25 commits

Author SHA1 Message Date
Folke Lemaitre
bc902f7032
feat(compat): added svim, a compatibility layer for Neovim. Closes #1321 2025-02-20 06:59:44 +01:00
Tristan Partin
a3b47e5202
feat(gitbrowse): add support for git.sr.ht (#1297)
Simply upstreaming this from my own config.

Signed-off-by: Tristan Partin <tristan@partin.io>
2025-02-19 15:15:21 +01:00
Iordanis Petkakis
2f3f080ede
fix(gitbrowse): previous logic always overwrote 'commit' (#1127)
## 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. -->
2025-02-13 12:04:09 +01:00
Ondrej Brablc
97fd57e8a0
fix(gitbrowse): add support for GitHub Enterprise Cloud repo url (#1089)
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`
2025-02-11 19:53:36 +01:00
qw457812
0bf47dc319
fix(gitbrowse): cwd for permalinks (#1038)
## 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.
2025-02-10 07:47:38 +01:00
Marc Schreiber
2a06e4ce99
feat(gitbrowse): open permalinks to files. Fixes #320 (#438)
## 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>
2025-02-09 23:05:25 +01:00
Folke Lemaitre
140204fde5 build: added metadata to plugins 2024-12-10 13:55:51 +01:00
Folke Lemaitre
a856952ab2
feat(gitbrowse): opts.notify 2024-12-02 10:24:19 +01:00
Folke Lemaitre
243655796e
fix(gitbrowse): opts.notify 2024-12-02 10:23:57 +01:00
Folke Lemaitre
f8949523ed
fix(gitbrowse): removed debug 2024-12-02 08:36:25 +01:00
Folke Lemaitre
0a48c2e726
feat(gitbrowse): url pattern can now also be a function 2024-12-02 08:35:51 +01:00
Folke Lemaitre
f03727c77f
feat(gitbrowse): added line_count. See #186 2024-12-02 08:22:28 +01:00
Folke Lemaitre
adf0433e8f
fix(gitbrowse): use line_start and line_end directly in patterns. Closes #186 2024-12-02 07:10:09 +01:00
Iordanis Petkakis
e5bc11e328
feat(gitbrowse): allow custom branch (#172)
## 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>
2024-12-01 18:11:59 +01:00
Iordanis Petkakis
59c8eb36ae
feat(gitbrowse): open commit when word is valid hash (#161)
## 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. -->
2024-11-27 18:22:14 +01:00
Krishna Balasubramanian
53441c9703
feat(gitbrowse): add Bitbucket URL patterns (#163)
## 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/162

https://github.com/folke/snacks.nvim/issues/138

## Screenshots

<!-- Add screenshots of the changes if applicable. -->

Co-authored-by: Krishna Balasubramanian <krishna@foxbots.com>
2024-11-26 09:17:30 +01:00
Zhou Fang
cfa7dea08a
fix(gitbrowse): fix the regex in url_patterns (#133)
## Description

The `remote` is used as a regex pattern, so the dot in the
`"github.com"` means any character. This PR correct the regexes in
default `url_patterns`.


aa38175c00/lua/snacks/gitbrowse.lua (L40-L49)


aa38175c00/lua/snacks/gitbrowse.lua (L68-L72)


Test code:

```lua
print(require("snacks").gitbrowse.get_url("https://githubacom.com/folke/snacks.nvim"))
```

## Related Issue(s)

<!--
  If this PR fixes any issues, please link to the issue here.
  - Fixes #<issue_number>
-->

## Screenshots

**Before**

![image](https://github.com/user-attachments/assets/899e8312-2e9d-44ed-92c1-e3b28cedc06c)

**After**

![image](https://github.com/user-attachments/assets/fc5610a9-8977-4369-aff2-861730083308)
2024-11-21 19:11:39 +01:00
Iordanis Petkakis
c29c0d4850
feat(gitbrowse): open also visual selection range (#89)
## 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>
2024-11-19 15:26:39 +01:00
Folke Lemaitre
4f99818b0a
fix: added compatibility with Neovim >= 0.9.4 2024-11-09 15:38:43 +01:00
Folke Lemaitre
7e6ea65f5f
docs: better docgen using treesitter 2024-11-09 14:42:09 +01:00
Folke Lemaitre
92da87c910
feat(gitbrowse): choose to open repo, branch or file. Closes #10. Closes #17 2024-11-08 10:39:55 +01:00
Folke Lemaitre
bbda275681
docs: gitbrowse 2024-11-06 13:38:51 +01:00
Folke Lemaitre
983621b0fe
docs: docgen 2024-11-06 11:27:52 +01:00
Folke Lemaitre
f4e0130ec3
feat: added notify 2024-11-04 18:56:19 +01:00
Folke Lemaitre
a638d8bafe
feat: added gitbrowse 2024-11-04 12:16:21 +01:00