jesseduffield.lazygit/pkg/commands
Stefan Haller 6b311ccb62 Fix quoting of shell commands on Windows
lazygit builds a shell command by interpolating Quote'd arguments into a
template and running the result via `cmd /c`. Several things were wrong
on Windows:

- Quote emitted bash-style `\"…\"` quoting, which cmd.exe doesn't
  understand. Making it usable at all previously required a fragile
  round-trip through str.ToArgv and re-escaping.
- The assembled command line was handed to `cmd /c` without `/s`, so
  cmd's default rules stripped the wrong quotes once the line contained
  more than two of them (e.g. a quoted editor path at a location with
  spaces, plus a quoted filename that also contains spaces).
- Shell metacharacters were escaped with `^` (`&` → `^&`, etc.), which
  neutralised command chaining, pipes, redirection and `%VAR%` expansion
  in custom commands.

Quote now emits the standard Windows convention directly, and NewShell
hands cmd.exe the fully-assembled line verbatim via SysProcAttr.CmdLine,
wrapped as `cmd /s /c "<command>"`. The /s flag strips exactly the outer
quote pair we add, leaving each argument's own quoting intact. With the
`^` escaping gone, metacharacters in a custom command reach cmd as the
author intended; this also removes the spurious `^` reported in #3092.

Fixes #5560
Fixes #2427
Fixes #4147

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:11:00 +02:00
..
direnv Offer direnv .envrc approval from inside lazygit 2026-06-04 09:05:01 +02:00
git_commands Only pass --no-optional-locks for background status refreshes 2026-06-19 18:14:24 +02:00
git_config Enable errorlint linter, and fix warnings 2025-06-30 18:30:11 +02:00
hosting_service Optimize regex compilations 2026-05-10 15:28:14 +02:00
models Add HeadCommitIdx helper function 2026-06-22 09:16:57 +02:00
oscommands Fix quoting of shell commands on Windows 2026-06-23 14:11:00 +02:00
patch Fix selection after staging an added line 2026-03-19 16:57:53 +01:00
testdata Support opening lazygit in a submodule 2019-05-12 17:59:49 +10:00
git.go Add GitHub commands and model for fetching PR status 2026-04-01 09:13:55 +02:00
git_cmd_obj_builder.go Remove the now-redundant gitCmdObjBuilder wrapper 2026-06-19 18:14:24 +02:00
git_cmd_obj_runner.go retry on ref lock errors during fetch/pull 2026-04-20 09:04:50 +02:00