Skip to content

apply on a single nonexistent target file fails #4968

@BradKnowles

Description

@BradKnowles

Describe the bug

I started a discussion over at #4952 and the recommendation was that I should file a bug report.

The gist is, when running chezmoi apply on a single that exists in source, but not yet in target, it returns an error. I noticed then when I was initializing my dotfiles on a new machine. I did init without immediately applying. Then I did one file as a test and it errored, saying the file didn't exist.

To reproduce

I can reproduce this is two ways, first on initial init and apply

chezmoi init BradKnowles/dotfiles
chezmoi apply .config/git/config


chezmoi: .config/git/config: open C:/Users/User/.config/git/config: The system cannot find the path specified.

or by creating a file manually in the source state and trying to apply

chezmoi cd
New-Item -Type File .\dot_config\git\config.tmpl -Force
exit

# Add data to file and save

cd ~
chezmoi apply .config/git/config

chezmoi: .config/git/config: open C:/Users/User/.config/git/config: The system cannot find the path specified.

Expected behavior

I expected the non-existent file to be created.

Output of command with the --verbose flag

$ chezmoi apply .config/git/config --verbose
NUL: --- Text

# text of converted template

chezmoi: .config/git/config: open C:/Users/User/.config/git/config: The system cannot find the path specified.

Output of chezmoi doctor

Details
$ chezmoi doctor

RESULT    CHECK                       MESSAGE
ok        version                     v2.69.4, commit c4c669c9f2f329233a85802014d26fba3c58a4a4, built at 2026-02-11T08:59:37Z, built by goreleaser
warning   latest-version              v2.70.0
ok        os-arch                     windows/amd64
ok        systeminfo                  Microsoft Windows 11 Enterprise Evaluation (10.0.22621 N/A Build 22621)
ok        go-version                  go1.25.7 (gc)
ok        executable                  ~/scoop/apps/chezmoi/current/chezmoi.exe
ok        upgrade-method              replace-executable
ok        config-file                 found ~/.config/chezmoi/chezmoi.yaml, last modified 2026-03-20T16:31:21-07:00
ok        source-dir                  ~/.local/share/chezmoi is a git working tree (clean)
ok        suspicious-entries          no suspicious entries
ok        working-tree                ~/.local/share/chezmoi is a git working tree (clean)
ok        dest-dir                    ~ is a directory
ok        symlink                     created symlink from .new-name to .old-name
ok        cd-command                  found C:/Program Files/WindowsApps/Microsoft.PowerShell_7.5.5.0_x64__8wekyb3d8bbwe/pwsh.exe
ok        cd-args                     pwsh -NoLogo
ok        diff-command                found ~/scoop/shims/difft.exe
ok        edit-command                found ~/scoop/shims/notepad4.exe
ok        edit-args                   notepad4
ok        git-command                 found ~/scoop/apps/git/current/cmd/git.exe, version 2.53.0
ok        merge-command               found C:/Program Files/Beyond Compare 5/BComp.exe
ok        shell-command               found C:/Windows/system32/cmd.exe
ok        shell-args                  'C:\\Windows\\system32\\cmd.exe'
ok        age-command                 found ~/scoop/shims/age.exe, version 1.3.1
ok        gpg-command                 found ~/scoop/shims/gpg.exe, version 2.4.9
info      pinentry-command            not set
info      1password-command           op not found in $PATH
info      bitwarden-command           bw not found in $PATH
info      bitwarden-secrets-command   bws not found in $PATH
info      dashlane-command            dcli not found in $PATH
info      doppler-command             doppler not found in $PATH
info      gopass-command              gopass not found in $PATH
info      keepassxc-command           keepassxc-cli not found in $PATH
info      keepassxc-db                not set
info      keeper-command              keeper not found in $PATH
info      lastpass-command            lpass not found in $PATH
info      pass-command                pass not found in $PATH
info      passhole-command            ph not found in $PATH
info      protonpass-command          pass-cli not found in $PATH
info      rbw-command                 rbw not found in $PATH
info      vault-command               vault not found in $PATH
info      secret-command              not set

Additional context

I'm running Windows 11 Pro and PowerShell 7.5.4.

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions