Skip to content

Accept diff writes to wrong path when using set autochdir #1377

Description

@mikeboiko

Description

When set autochdir is enabled, accepting a diff sometimes writes to the wrong file path.

Specifically, when switching folders, the CopilotChat buffer’s working directory does not update correctly, which causes diffs to be applied to the wrong file.


Steps to Reproduce

  1. Enable set autochdir in Neovim.
  2. Open file ~/git/Test/names1.json.
  3. Open Copilot Chat, run pwd inside the CopilotChat window → directory is ~/git/Test.
    • ✅ Accepting a diff at this point works as expected.
  4. Now open another file in a different folder (in the original window): ~/git/Test/test/names2.json.
  5. Run pwd inside the CopilotChat window → directory is still ~/git/Test (does not change).
  6. Ask a question in Copilot Chat and accept the diff.

Expected:
The diff should be written to ~/git/Test/test/names2.json.

Actual:
The diff is incorrectly written to ~/git/Test/names1.json.

Image

Environment

  • Neovim version:
NVIM v0.11.3
Build type: RelWithDebInfo
LuaJIT 2.1.1753364724
Run "nvim -V1 -v" for more info
  • CopilotChat.nvim version: main/72216c06fa2ce82406c3406d898a83c02db412a7
  • OS: Linux

Additional Notes

  • It seems the working directory inside CopilotChat is not updating properly with autochdir. This causes mismatches between the current buffer path and where diffs are applied. If I disable autochdir in `nvim, everything starts working properly.
  • I don't remember when this started being an issue, but this didn't occur at one point.
  • Love the plugin... keep up the great work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions