Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] chezmoi source-path returns source directory path if used on file in exact directory #2977

Closed
aarondill opened this issue May 8, 2023 · 5 comments · Fixed by #2980
Closed
Labels
bug Something isn't working

Comments

@aarondill
Copy link
Contributor

Describe the bug

Running chezmoi source-path FILE on a target file in an exact_ source directory returns the source-dir path, same as if no arguments were given.
NOTE: this also affects chezmoi edit FILE.

To reproduce

$ cd "$(chezmoi target-path)"
$ mkdir TEST
$ chezmoi add --exact TEST/
$ touch TEST/file
$ chezmoi source-path TEST/file
/home/aaron/.local/share/chezmoi/source
$ chezmoi edit TEST/file
# Opens /home/aaron/.local/share/chezmoi/source in $EDITOR

Expected behavior

One of:

  • Return the eventual location: /home/$USER/.local/share/chezmoi/source/exact_TEST/empty_file
  • chezmoi: TEST/file: not in source state and error 1 like other files

Output of command with the --verbose flag

Same as above

$ chezmoi --verbose source-path TEST/file
/home/aaron/.local/share/chezmoi/source

Output of chezmoi doctor

$ chezmoi doctor
RESULT    CHECK                MESSAGE
ok        version              v2.33.3, commit fe6010e8b2518ddabfcd5f58236763b4f2e90ff8, built at 2023-04-21T20:41:23Z, built by goreleaser
warning   latest-version       v2.33.4
ok        os-arch              linux/amd64 (Ubuntu 22.04.2 LTS (Jammy Jellyfish))
ok        uname                Linux aaron-HP-Laptop-15-dy2xxx 5.19.0-41-generic #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
ok        go-version           go1.20.3 (gc)
ok        executable           ~/.local/bin/chezmoi
ok        upgrade-method       replace-executable
ok        config-file          ~/.config/chezmoi/chezmoi.toml, last modified 2023-05-02T22:18:31-05: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        umask                002
ok        cd-command           found /bin/bash
ok        cd-args              /bin/bash
info      diff-command         not set
ok        edit-command         found /usr/bin/vim
ok        edit-args            /usr/bin/vim
ok        git-command          found /usr/bin/git, version 2.34.1
warning   merge-command        vimdiff not found in $PATH
ok        shell-command        found /bin/bash
ok        shell-args           /bin/bash
ok        age-command          found /usr/bin/age, version 1.0.0
ok        gpg-command          found /usr/bin/gpg, version 2.2.27
info      pinentry-command     not set
info      1password-command    op not found in $PATH
ok        bitwarden-command    found /usr/local/bin/bw, version 2023.4.0
info      dashlane-command     dcli 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      rbw-command          rbw not found in $PATH
info      vault-command        vault not found in $PATH
info      secret-command       not set

Additional context

This affects my workflow because I shadow my editor (vim) with a function like this:

 vim() {
  # If AN argument is passed, and is in repo
  if [ -n "$*" ] && chezmoi source-path "$@" &>/dev/null; then
    chezmoi edit -a -- "$@"
    # Re-add files, incase another file was updated locally
    chezmoi re-add
  else
    command vim "$@"
  fi
}

which saves me from thinking about using chezmoi edit or ordinary vim. However, when chezmoi edit returns the source path, this results in my file being deleted, without a chance to edit it.

For this purpose exactly, I would prefer if source-path returned an error, however that's my own issue and I can just add a check to ensure it's actually present in the source directory.

@aarondill
Copy link
Contributor Author

aarondill commented May 8, 2023

if the file doesn't exist at all, chezmoi: TEST/file: not in source state is returned:

$ cd "$(chezmoi target-path)"
$ mkdir TEST
$ chezmoi add --exact TEST/
$ chezmoi source-path TEST/file
chezmoi: TEST/file: not in source state

@twpayne
Copy link
Owner

twpayne commented May 8, 2023

I think this is the same as #2954, which is fixed in #2967 and already released in 2.33.4.

@aarondill

This comment was marked as outdated.

@aarondill
Copy link
Contributor Author

Updated, and issue is still reproducible.

chezmoi doctor
$ chezmoi doctor
RESULT    CHECK                MESSAGE
ok        version              v2.33.4, commit b9603835e602a317d4cca08a903add9f8713e88e, built at 2023-05-02T14:54:35Z, built by goreleaser
ok        latest-version       v2.33.4
ok        os-arch              linux/amd64 (Ubuntu 22.04.2 LTS (Jammy Jellyfish))
ok        uname                Linux aaron-HP-Laptop-15-dy2xxx 5.19.0-41-generic #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
ok        go-version           go1.20.3 (gc)
ok        executable           ~/.local/bin/chezmoi
ok        upgrade-method       replace-executable
ok        config-file          ~/.config/chezmoi/chezmoi.toml, last modified 2023-05-02T22:18:31-05: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        umask                002
ok        cd-command           found /bin/bash
ok        cd-args              /bin/bash
info      diff-command         not set
ok        edit-command         found /usr/bin/vim
ok        edit-args            /usr/bin/vim
ok        git-command          found /usr/bin/git, version 2.34.1
warning   merge-command        vimdiff not found in $PATH
ok        shell-command        found /bin/bash
ok        shell-args           /bin/bash
ok        age-command          found /usr/bin/age, version 1.0.0
ok        gpg-command          found /usr/bin/gpg, version 2.2.27
info      pinentry-command     not set
info      1password-command    op not found in $PATH
ok        bitwarden-command    found /usr/local/bin/bw, version 2023.4.0
info      dashlane-command     dcli 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      rbw-command          rbw not found in $PATH
info      vault-command        vault not found in $PATH
info      secret-command       not set

@twpayne
Copy link
Owner

twpayne commented May 9, 2023

Thanks for testing with the latest version. #2980 should fix it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants