Skip to content

toggle_cwd action doesn't work for git pickers #2646

@aweis89

Description

@aweis89

Description

The toggle_cwd action (defined in LazyVim's snacks_picker config) doesn't work for git pickers (git_status, git_log, git_diff, etc.).

Expected Behavior

Pressing the toggle_cwd keybinding should toggle between LazyVim.root() and vim.fn.getcwd() for filtering/display purposes, similar to how it works for files, grep, and other pickers.

Actual Behavior

The cwd is immediately reset back to git root, making the toggle ineffective.

Root Cause

The git picker sources unconditionally override the picker's cwd with the git root. For example, in lua/snacks/picker/source/git.lua line 227-228 (git_status):

local cwd = ctx:git_root()
ctx.picker:set_cwd(cwd)

When toggle_cwd calls p:set_cwd() followed by p:find(), the finder immediately overwrites the cwd back to git root.

The same pattern exists in other git sources:

  • git_log (line 269-270)
  • git_diff (line 321)
  • git_stash (line 367)

Suggested Fix

One option would be to only set cwd to git root if opts.cwd wasn't explicitly provided:

if not opts.cwd then
  local cwd = ctx:git_root()
  ctx.picker:set_cwd(cwd)
end

This matches the pattern already used in git_files and git_grep (lines 42-45, 87-89).

Environment

  • snacks.nvim: latest
  • LazyVim: latest
  • neovim: 0.10+

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleThis issue or PR has been inactive for a whilewontfixThis issue will not be fixed or implemented

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions