From 7ec2d7f22d3f489c7bbc736b958bffb05aff90f6 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 4 Nov 2024 12:14:02 +0100 Subject: [PATCH] feat(snacks): use gitbrowse --- lua/lazyvim/config/keymaps.lua | 2 +- lua/lazyvim/util/init.lua | 1 - lua/lazyvim/util/lazygit.lua | 69 ---------------------------------- tests/util/lazygit_spec.lua | 42 --------------------- 4 files changed, 1 insertion(+), 113 deletions(-) delete mode 100644 lua/lazyvim/util/lazygit.lua delete mode 100644 tests/util/lazygit_spec.lua diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index bf9e9b2f..423d512f 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -133,7 +133,7 @@ end map("n", "gg", function() Snacks.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) map("n", "gG", function() Snacks.lazygit() end, { desc = "Lazygit (cwd)" }) map("n", "gb", function() Snacks.git.blame_line() end, { desc = "Git Blame Line" }) -map("n", "gB", LazyVim.lazygit.browse, { desc = "Git Browse" }) +map("n", "gB", function() Snacks.gitbrowse() end, { desc = "Git Browse" }) map("n", "gf", function() Snacks.lazygit.log_file() end, { desc = "Lazygit Current File History" }) map("n", "gl", function() Snacks.lazygit.log({ cwd = LazyVim.root.git() }) end, { desc = "Lazygit Log" }) map("n", "gL", function() Snacks.lazygit.log() end, { desc = "Lazygit Log (cwd)" }) diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 106cbdc0..8ea1ab79 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -6,7 +6,6 @@ local LazyUtil = require("lazy.core.util") ---@field lsp lazyvim.util.lsp ---@field root lazyvim.util.root ---@field terminal lazyvim.util.terminal ----@field lazygit lazyvim.util.lazygit ---@field toggle lazyvim.util.toggle ---@field format lazyvim.util.format ---@field plugin lazyvim.util.plugin diff --git a/lua/lazyvim/util/lazygit.lua b/lua/lazyvim/util/lazygit.lua deleted file mode 100644 index 125c66c7..00000000 --- a/lua/lazyvim/util/lazygit.lua +++ /dev/null @@ -1,69 +0,0 @@ ----@class lazyvim.util.lazygit -local M = {} - --- stylua: ignore -M.remote_patterns = { - { "^(https?://.*)%.git$" , "%1" }, - { "^git@(.+):(.+)%.git$" , "https://%1/%2" }, - { "^git@(.+):(.+)$" , "https://%1/%2" }, - { "^git@(.+)/(.+)$" , "https://%1/%2" }, - { "^ssh://git@(.*)$" , "https://%1" }, - { "ssh%.dev%.azure%.com/v3/(.*)/(.*)$", "dev.azure.com/%1/_git/%2" }, - { "^https://%w*@(.*)" , "https://%1" }, - { "^git@(.*)" , "https://%1" }, - { ":%d+" , "" }, - { "%.git$" , "" }, -} - ----@param remote string -function M.get_url(remote) - local ret = remote - for _, pattern in ipairs(M.remote_patterns) do - ret = ret:gsub(pattern[1], pattern[2]) - end - return ret:find("https://") == 1 and ret or ("https://%s"):format(ret) -end - -function M.browse() - local lines = require("lazy.manage.process").exec({ "git", "remote", "-v" }) - local remotes = {} ---@type {name:string, url:string}[] - - for _, line in ipairs(lines) do - local name, remote = line:match("(%S+)%s+(%S+)%s+%(fetch%)") - if name and remote then - local url = M.get_url(remote) - if url then - table.insert(remotes, { - name = name, - url = url, - }) - end - end - end - - local function open(remote) - if remote then - LazyVim.info(("Opening [%s](%s)"):format(remote.name, remote.url)) - if vim.fn.has("nvim-0.10") == 0 then - require("lazy.util").open(remote.url, { system = true }) - return - end - vim.ui.open(remote.url) - end - end - - if #remotes == 0 then - return LazyVim.error("No git remotes found") - elseif #remotes == 1 then - return open(remotes[1]) - end - - vim.ui.select(remotes, { - prompt = "Select remote to browse", - format_item = function(item) - return item.name .. (" "):rep(8 - #item.name) .. " 🔗 " .. item.url - end, - }, open) -end - -return M diff --git a/tests/util/lazygit_spec.lua b/tests/util/lazygit_spec.lua deleted file mode 100644 index 518e886a..00000000 --- a/tests/util/lazygit_spec.lua +++ /dev/null @@ -1,42 +0,0 @@ ----@module "luassert" - -_G.LazyVim = require("lazyvim.util") - --- stylua: ignore -local git_remotes_cases = { - ["https://github.com/LazyVim/LazyVim.git"] = "https://github.com/LazyVim/LazyVim", - ["https://github.com/LazyVim/LazyVim"] = "https://github.com/LazyVim/LazyVim", - ["git@github.com:LazyVim/LazyVim"] = "https://github.com/LazyVim/LazyVim", - ["git@ssh.dev.azure.com:v3/neovim-org/owner/repo"] = "https://dev.azure.com/neovim-org/owner/_git/repo", - ["https://folkelemaitre@bitbucket.org/samiulazim/neovim.git"] = "https://bitbucket.org/samiulazim/neovim", - ["git@bitbucket.org:samiulazim/neovim.git"] = "https://bitbucket.org/samiulazim/neovim", - ["git@gitlab.com:inkscape/inkscape.git"] = "https://gitlab.com/inkscape/inkscape", - ["https://gitlab.com/inkscape/inkscape.git"] = "https://gitlab.com/inkscape/inkscape", - ["git@github.com:torvalds/linux.git"] = "https://github.com/torvalds/linux", - ["https://github.com/torvalds/linux.git"] = "https://github.com/torvalds/linux", - ["git@bitbucket.org:team/repo.git"] = "https://bitbucket.org/team/repo", - ["https://bitbucket.org/team/repo.git"] = "https://bitbucket.org/team/repo", - ["git@gitlab.com:example-group/example-project.git"] = "https://gitlab.com/example-group/example-project", - ["https://gitlab.com/example-group/example-project.git"] = "https://gitlab.com/example-group/example-project", - ["git@ssh.dev.azure.com:v3/org/project/repo"] = "https://dev.azure.com/org/project/_git/repo", - ["https://username@dev.azure.com/org/project/_git/repo"] = "https://dev.azure.com/org/project/_git/repo", - ["ssh://git@ghe.example.com:2222/org/repo.git"] = "https://ghe.example.com/org/repo", - ["https://ghe.example.com/org/repo.git"] = "https://ghe.example.com/org/repo", - ["git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo"] = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo", - ["https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo"] = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo", - ["ssh://git@source.developers.google.com:2022/p/project/r/repo"] = "https://source.developers.google.com/p/project/r/repo", - ["https://source.developers.google.com/p/project/r/repo"] = "https://source.developers.google.com/p/project/r/repo", - ["git@git.sr.ht:~user/repo"] = "https://git.sr.ht/~user/repo", - ["https://git.sr.ht/~user/repo"] = "https://git.sr.ht/~user/repo", - ["git@git.sr.ht:~user/another-repo"] = "https://git.sr.ht/~user/another-repo", - ["https://git.sr.ht/~user/another-repo"] = "https://git.sr.ht/~user/another-repo", -} - -describe("util.lazygit", function() - for remote, expected in pairs(git_remotes_cases) do - it("should parse git remote " .. remote, function() - local url = LazyVim.lazygit.get_url(remote) - assert.are.equal(expected, url) - end) - end -end)