From a67c42d45323d714c1a6b5417e4a8c5077032386 Mon Sep 17 00:00:00 2001 From: zdm Date: Thu, 1 May 2025 18:16:01 +0300 Subject: [PATCH 1/5] feat: add msys2 support --- lua/diffview/vcs/adapters/git/init.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lua/diffview/vcs/adapters/git/init.lua b/lua/diffview/vcs/adapters/git/init.lua index 3a137bc9..48651289 100644 --- a/lua/diffview/vcs/adapters/git/init.lua +++ b/lua/diffview/vcs/adapters/git/init.lua @@ -177,7 +177,16 @@ local function get_toplevel(path) if code ~= 0 then return nil end - return out[1] and vim.trim(out[1]) + + local path = out[1] and vim.trim(out[1]) + + if path then + if vim.fn.has('win32') == 1 and string.sub(path, 1, 1) == '/' then + path = string.gsub(string.sub(path, 2, 2) .. ':' .. string.sub(path, 3), '/', '\\') + end + end + + return path end ---Try to find the top-level of a working tree by using the given indicative @@ -279,7 +288,16 @@ function GitAdapter:get_dir(path) if code ~= 0 then return nil end - return out[1] and vim.trim(out[1]) + + local path = out[1] and vim.trim(out[1]) + + if path then + if vim.fn.has('win32') == 1 and string.sub(path, 1, 1) == '/' then + path = string.gsub(string.sub(path, 2, 2) .. ':' .. string.sub(path, 3), '/', '\\') + end + end + + return path end ---Verify that a given git rev is valid. From 5f525978ed53f72879a6ed21e5ff146b131263d2 Mon Sep 17 00:00:00 2001 From: zdm Date: Thu, 1 May 2025 18:18:41 +0300 Subject: [PATCH 2/5] feat: add msys2 support --- README.md | 2 +- lua/diffview/debounce.lua | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 9298e1f5..bec2c23e 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Plug 'sindrets/diffview.nvim' ```lua -- Packer -use "sindrets/diffview.nvim" +use "sindrets/diffview.nvim" ``` ## Merge Tool diff --git a/lua/diffview/debounce.lua b/lua/diffview/debounce.lua index 74fc51f5..29535e1c 100644 --- a/lua/diffview/debounce.lua +++ b/lua/diffview/debounce.lua @@ -243,4 +243,3 @@ function M.set_timeout(func, delay) end return M - From f1f1c0d6002d01888cc8cc514ff6343df59f722c Mon Sep 17 00:00:00 2001 From: zdm Date: Thu, 1 May 2025 20:33:43 +0300 Subject: [PATCH 3/5] chore: deduplicate code --- lua/diffview/vcs/adapters/git/init.lua | 30 +++++++++++--------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lua/diffview/vcs/adapters/git/init.lua b/lua/diffview/vcs/adapters/git/init.lua index 48651289..2d5c5344 100644 --- a/lua/diffview/vcs/adapters/git/init.lua +++ b/lua/diffview/vcs/adapters/git/init.lua @@ -25,6 +25,16 @@ local logger = DiffviewGlobal.logger local pl = lazy.access(utils, "path") ---@type PathLib local uv = vim.loop +local function normalize_cygwin_path(path) + path = path and vim.trim(path) + + if path and vim.fn.has('win32') == 1 and string.sub(path, 1, 1) == '/' then + path = string.gsub(string.sub(path, 2, 2) .. ':' .. string.sub(path, 3), '/', '\\') + end + + return path +end + local M = {} ---@class GitAdapter : VCSAdapter @@ -178,15 +188,7 @@ local function get_toplevel(path) return nil end - local path = out[1] and vim.trim(out[1]) - - if path then - if vim.fn.has('win32') == 1 and string.sub(path, 1, 1) == '/' then - path = string.gsub(string.sub(path, 2, 2) .. ':' .. string.sub(path, 3), '/', '\\') - end - end - - return path + return normalize_cygwin_path(out[1]) end ---Try to find the top-level of a working tree by using the given indicative @@ -289,15 +291,7 @@ function GitAdapter:get_dir(path) return nil end - local path = out[1] and vim.trim(out[1]) - - if path then - if vim.fn.has('win32') == 1 and string.sub(path, 1, 1) == '/' then - path = string.gsub(string.sub(path, 2, 2) .. ':' .. string.sub(path, 3), '/', '\\') - end - end - - return path + return normalize_cygwin_path(out[1]) end ---Verify that a given git rev is valid. From b02a0861dccf049687661f3d0b86c537a6b07cf9 Mon Sep 17 00:00:00 2001 From: zdm Date: Fri, 2 May 2025 07:39:23 +0300 Subject: [PATCH 4/5] chore: improve cygpath conversion --- .editorconfig | 10 ++++++++++ lua/diffview/vcs/adapters/git/init.lua | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..e2612ae6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = off diff --git a/lua/diffview/vcs/adapters/git/init.lua b/lua/diffview/vcs/adapters/git/init.lua index 2d5c5344..93e7252d 100644 --- a/lua/diffview/vcs/adapters/git/init.lua +++ b/lua/diffview/vcs/adapters/git/init.lua @@ -25,11 +25,21 @@ local logger = DiffviewGlobal.logger local pl = lazy.access(utils, "path") ---@type PathLib local uv = vim.loop +local has_cygpath local function normalize_cygwin_path(path) path = path and vim.trim(path) if path and vim.fn.has('win32') == 1 and string.sub(path, 1, 1) == '/' then - path = string.gsub(string.sub(path, 2, 2) .. ':' .. string.sub(path, 3), '/', '\\') + if has_cygpath == nil then + has_cygpath = vim.fn.executable('cygpath') == 1 + end + + if has_cygpath then + path = vim.fn.system({"cygpath", "--absolute", "--windows", path}) + + -- remove "\n" + path = string.sub(path, 1, #path -1) + end end return path From 06232a83781ac7423273c5ed4a0e2b53e69eff8f Mon Sep 17 00:00:00 2001 From: zdm Date: Fri, 2 May 2025 07:59:32 +0300 Subject: [PATCH 5/5] chore: improve cygpath conversion --- lua/diffview/vcs/adapters/git/init.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/diffview/vcs/adapters/git/init.lua b/lua/diffview/vcs/adapters/git/init.lua index 93e7252d..84aa0afe 100644 --- a/lua/diffview/vcs/adapters/git/init.lua +++ b/lua/diffview/vcs/adapters/git/init.lua @@ -27,8 +27,6 @@ local uv = vim.loop local has_cygpath local function normalize_cygwin_path(path) - path = path and vim.trim(path) - if path and vim.fn.has('win32') == 1 and string.sub(path, 1, 1) == '/' then if has_cygpath == nil then has_cygpath = vim.fn.executable('cygpath') == 1