jesseduffield / lazygit

simple terminal UI for git commands
MIT License
53.65k stars 1.87k forks source link

Special characters are not escaped when excluding files #4075

Open Armadillidiid opened 4 days ago

Armadillidiid commented 4 days ago

Describe the bug

When attempting to exclude a file with square brackets or parenthesis in the file path, LazyGit appends the path to .git/info/exclude without escaping the special characters. This causes the exclusion not to work as Git interprets square brackets as part of a regular expression pattern.

To Reproduce

Steps to reproduce the behavior:

  1. Open LazyGit in a Next.js project.
  2. Navigate to a file with a path that includes square brackets or parenthesis e.g., src/app/(fullscreen)/dashboard/screening/campaigns/[campaignId]/page.ts
  3. Use LazyGit to exclude the file.
  4. Check .git/info/exclude to see the appended path.

Expected behavior

The file path should be escaped properly in .git/info/exclude, ensuring that special characters such as square brackets ([ ]) are treated literally. For example:

src/app/\(fullscreen\)/dashboard/screening/campaigns/\[campaignId\]/page..ts

Screenshots

N/A

Desktop (please complete the following information):

OS: [Your OS, e.g., Ubuntu 22.04]
Lazygit Version: commit=v0.44.1, build date=2024-09-18T13:19:48Z, build source=binaryRelease, version=0.44.1, os=linux, arch=amd64, git version=2.47.0
Git Version:  2.47.0

Additional context

N/A

GhostFire90 commented 3 days ago

Before i fork to work on this could you show the current behavior? Just to make sure i understand

mark2185 commented 3 days ago

~Instead of escaping characters, could the entire path just be quoted?~

EDIT: looks like it can't.