jesseduffield.lazygit/pkg
Vadym d44c7cfe64 fix(windows): set console title via SetConsoleTitleW instead of shelling out to cmd /c title
Fixes #5766.

UpdateWindowTitle built a `title <repo-name> - Lazygit` string and ran it
through `cmd /c "title ..."`. When the current directory's basename contains
a cmd.exe metacharacter such as `&`, cmd.exe treats it as a command
separator: "test&aaa" gets split into `title test` and `aaa`, and cmd.exe
then tries to execute `aaa` as a program. That fails with:

    'aaa' n'est pas reconnu en tant que commande interne ou externe...

which lazygit's error handling surfaced as an uncaught error, crashing the
whole run (and, per the second half of the report, closing the parent
shell). This reproduces both ways described in the issue: launching lazygit
directly inside a folder with '&' in its name, and opening such a repo from
the recent-repos menu.

Fix

UpdateWindowTitle now calls the Win32 SetConsoleTitleW API directly via
syscall.NewLazyDLL/kernel32.dll (the same mechanism pkg/gocui/gui_windows.go
already uses for GetConsoleScreenBufferInfo), instead of building a shell
command string and handing it to cmd.exe. This sidesteps cmd.exe's argument
parsing entirely — the title is passed to the OS as a UTF-16 string, so it's
set verbatim regardless of what characters the directory name contains. No
shell, no quoting rules, no injection surface.

Testing

    go build ./...
    GOOS=windows GOARCH=amd64 go build ./...
    GOOS=windows GOARCH=amd64 go vet ./pkg/commands/oscommands/...
    GOOS=windows GOARCH=amd64 go test -c ./pkg/commands/oscommands/   # compiles
    go test ./pkg/commands/oscommands/... -v                          # passes on darwin
    go test <all non-integration packages> -count=1                  # all green

I don't have a Windows machine to run the test binary on directly, but I
cross-compiled the package (and its test binary) for windows/amd64 to
confirm it builds and type-checks cleanly, and the two new tests below will
execute for real on the windows-latest CI runner this repo already uses.

New tests in pkg/commands/oscommands/os_windows_test.go (windows-only,
build-tagged, same as the existing file):
- TestUpdateWindowTitle_NameWithAmpersand: chdirs into a directory named
  "test&aaa" (the exact string from the report) and asserts
  UpdateWindowTitle no longer errors, then reads the title back with
  GetConsoleTitleW and asserts it's the literal, unsplit directory name -
  reproducing #5766 and proving it's fixed.
- TestUpdateWindowTitle_PlainName: sanity check that the ordinary case
  (no special characters) still produces the expected "<name> - Lazygit"
  title.

Both tests skip gracefully (rather than fail) if GetConsoleTitleW is
unavailable in the CI environment (e.g. no attached console), so they can't
produce a false failure unrelated to this fix.
2026-07-23 18:37:51 +02:00
..
app Allow overriding the platform used for default keybindings 2026-07-03 19:08:22 +02:00
cheatsheet Render every key for a binding in the cheatsheet 2026-05-25 15:18:18 +02:00
commands fix(windows): set console title via SetConsoleTitleW instead of shelling out to cmd /c title 2026-07-23 18:37:51 +02:00
common Move NewDummyCommon to pkg/common 2025-05-06 09:43:26 +02:00
config Support a {{diffContext}} template variable in external diff command 2026-07-23 17:13:02 +02:00
constants Make the links in the status panel point to the current version rather than master 2024-03-22 08:13:59 +01:00
env Support bare worktrees where worktree does not have its own .git file 2023-08-07 22:40:53 +10:00
fakes Modernize all codes 2025-11-15 10:46:23 +01:00
gocui Schedule a redraw when resuming from suspension 2026-07-20 14:23:09 +02:00
gui Never hand NewCmdTask a nil reader when a command fails to start 2026-07-23 17:31:26 +02:00
i18n Show a waiting status while creating a branch 2026-07-17 12:32:32 +02:00
integration Block input while the refresh after moving a rebase todo is in flight 2026-07-22 08:31:11 +02:00
jsonschema Fold legacy quit-alt1 into the multi-key quit binding 2026-05-25 15:32:47 +02:00
logs Fix Windows linter errors 2026-06-16 16:21:13 +02:00
snake Enable intrange linter, and fix warnings 2025-06-30 18:30:11 +02:00
tasks Handle a command task's end-of-input on the UI thread 2026-07-17 12:35:54 +02:00
theme Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00
updates Change direct access to Common.UserConfig to a getter 2024-08-18 10:24:52 +02:00
utils Expand a leading ~ in worktree paths to the home directory 2026-07-03 18:53:05 +02:00