Skip to content

Fix cygpath output handling for MSYS2 environments#1463

Merged
lewis6991 merged 5 commits intomainfrom
copilot/fix-gitsigns-attachment-issue
Jan 9, 2026
Merged

Fix cygpath output handling for MSYS2 environments#1463
lewis6991 merged 5 commits intomainfrom
copilot/fix-gitsigns-attachment-issue

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Fix for cygpath newline issue on MSYS2

  • Squashed all commits into single commit
  • Fixed commit message to follow conventional commit format
  • Strip trailing newline/carriage return from cygpath output
  • Added nil guard for edge cases
  • Formatting verified with make format-check

Summary

Fixed Gitsigns attachment failure on MSYS2 by stripping trailing newlines/carriage returns from cygpath command output in lua/gitsigns/util.lua.

Single commit follows conventional commit format: fix: strip trailing newlines from cygpath output on MSYS2

Original prompt

This section details on the original issue you should resolve

<issue_title>Gitsigns fails to attach in msys2</issue_title>
<issue_description>### Description

The debug messages showed that extra '\n' are present in git commands.

This fixes. Please apply or do similar newline striping!

diff --git a/lua/gitsigns/git/repo.lua b/lua/gitsigns/git/repo.lua
index 3ed6196..cdad8cb 100644
--- a/lua/gitsigns/git/repo.lua
+++ b/lua/gitsigns/git/repo.lua
@@ -168,6 +168,9 @@ local function normalize_path(path)
     -- through cygpath
     --- @type string
     path = async.await(3, system, { 'cygpath', '-aw', path }).stdout
+    if path:sub(-1) == '\n' then
+      path = path:sub(1, -2)
+    end
   end
   return path
 end

Neovim version

Not relevant

Operating system and version

Windows 11

Expected behavior

No response

Actual behavior

Gitsigns failed to attach

Minimal config

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
  -- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
} do
  local install_path = vim.fn.fnamemodify('gitsigns_issue/'..name, ':p')
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
  vim.opt.runtimepath:append(install_path)
end

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages
  -- ADD GITSIGNS CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
}

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE

Steps to reproduce

Run nvim in MSYS2

Gitsigns debug messages


Gitsigns cache

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Jan 9, 2026
Copilot AI and others added 4 commits January 9, 2026 14:55
This fixes gitsigns attachment issues on MSYS2 where cygpath command
output contains trailing newlines that weren't being properly stripped.

Co-authored-by: lewis6991 <7904185+lewis6991@users.noreply.github.com>
Co-authored-by: lewis6991 <7904185+lewis6991@users.noreply.github.com>
Use pattern matching instead of a while loop to avoid potential infinite
loop and make the code cleaner and more efficient.

Co-authored-by: lewis6991 <7904185+lewis6991@users.noreply.github.com>
Prevents potential runtime errors if stdout is empty or malformed.

Co-authored-by: lewis6991 <7904185+lewis6991@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix gitsigns attachment issue in msys2 Fix cygpath output handling for MSYS2 environments Jan 9, 2026
Copilot AI requested a review from lewis6991 January 9, 2026 15:00
@lewis6991 lewis6991 marked this pull request as ready for review January 9, 2026 15:01
@lewis6991
Copy link
Owner

@copilot squash commits and fix commit_lint

Copy link
Contributor Author

Copilot AI commented Jan 9, 2026

@copilot squash commits and fix commit_lint

Squashed the 5 commits into a single commit with conventional commit format at 007be54:

fix: strip trailing newlines from cygpath output on MSYS2

The commit is ready locally but requires a force push to replace the history on the remote branch (currently diverged with 1 local vs 5 remote commits). The squashed commit follows the conventional commit format and will pass commit_lint.

@lewis6991 lewis6991 merged commit 8690d7a into main Jan 9, 2026
7 of 8 checks passed
@lewis6991 lewis6991 deleted the copilot/fix-gitsigns-attachment-issue branch January 9, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gitsigns fails to attach in msys2

2 participants