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

Unable to add file with chezmoi #2154

Closed
shadycuz opened this issue Jun 19, 2022 · 3 comments · Fixed by #2161
Closed

Unable to add file with chezmoi #2154

shadycuz opened this issue Jun 19, 2022 · 3 comments · Fixed by #2161
Labels
enhancement New feature or request

Comments

@shadycuz
Copy link

Describe the bug

I'm trying to add a file to chezmoi, the file does not get added and no error is returned.

To reproduce

shadycuz@La-Laptop-wsl:~$ touch ~/.desktop
shadycuz@La-Laptop-wsl:~$ chezmoi add ~/.desktop
shadycuz@La-Laptop-wsl:~$ chezmoi edit ~/.desktop
chezmoi: .desktop: not in source state
shadycuz@La-Laptop-wsl:~$ chezmoi cd
shadycuz@La-Laptop-wsl:~/.local/share/chezmoi$ ls
dot_bashrc  run_once_setup.sh.tmpl
shadycuz@La-Laptop-wsl:~/.local/share/chezmoi$ exit
shadycuz@La-Laptop-wsl:~$ chezmoi -v add ~/.desktop
shadycuz@La-Laptop-wsl:~$ echo $?
0

Expected behavior

I expected that my new file would be added to the .local/share/chezmoi directory and ready to be worked on.

Output of command with the --verbose flag

Nothing

Output of chezmoi doctor

shadycuz@La-Laptop-wsl:~$ chezmoi doctor
RESULT   CHECK                MESSAGE
ok       version              v2.17.1, commit 565cbbe117746aa6bfec5f2cee20ae4cbbb5e645, built at 2022-05-30T10:24:34Z, built by goreleaser
ok       latest-version       v2.17.1
ok       os-arch              linux/amd64 (Ubuntu 22.04 LTS (Jammy Jellyfish))
ok       uname                Linux La-Laptop-wsl 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
ok       go-version           go1.18.2 (gc)
ok       executable           ~/bin/chezmoi
ok       upgrade-method       replace-executable
ok       config-file          no config file found
ok       source-dir           ~/.local/share/chezmoi is a directory
ok       suspicious-entries   no suspicious entries
ok       working-tree         ~/.local/share/chezmoi is a directory
ok       dest-dir             ~ is a directory
ok       shell-command        found /bin/bash
ok       shell-args           /bin/bash
ok       cd-command           found /bin/bash
ok       cd-args              /bin/bash
ok       edit-command         found /usr/bin/vi
ok       edit-args            /usr/bin/vi
info     diff-command         not set
ok       umask                002
ok       git-command          found /usr/bin/git, version 2.34.1
ok       merge-command        found /usr/bin/vimdiff
info     age-command          age not found in $PATH
ok       gpg-command          found /usr/bin/gpg, version 2.2.27
info     pinentry-command     not set
info     1password-command    op not found in $PATH
info     bitwarden-command    bw not found in $PATH
info     gopass-command       gopass not found in $PATH
info     keepassxc-command    keepassxc-cli not found in $PATH
info     keeper-command       keeper not found in $PATH
info     keepassxc-db         not set
info     lastpass-command     lpass not found in $PATH
info     pass-command         pass not found in $PATH
info     vault-command        vault not found in $PATH
info     secret-command       not set

Additional context

It appears that it works if the file has contents.

shadycuz@La-Laptop-wsl:~$ echo "foo" > .desktop
shadycuz@La-Laptop-wsl:~$ chezmoi -v add .desktop
diff --git a/dot_desktop b/dot_desktop
new file mode 100664
index 0000000000000000000000000000000000000000..257cc5642cb1a054f08cc83f2d943e56fd3ebe99
--- /dev/null
+++ b/dot_desktop
@@ -0,0 +1 @@
+foo

Should I open a PR that adds a chezmoi touch command? I would really like to contribute =)

@twpayne twpayne added the support Support request label Jun 19, 2022
@twpayne
Copy link
Owner

twpayne commented Jun 19, 2022

By default, chezmoi removes files whose target contents are empty, unless they have the empty_ attribute. As ~/.desktop is empty, chezmoi add doesn't add it. The following does work:

$ touch ~/.desktop
$ chezmoi add --empty ~/.desktop
$ ls $(chezmoi source-path ~/.desktop)
$HOME/.local/share/chezmoi/home/empty_dot_desktop

Thanks for the offer of contributing. I don't think a chezmoi touch command is needed, but some improved documentation about the empty_ attribute would be appreciated.

@shadycuz
Copy link
Author

Ahh I see, --empty flag.

Make sense, what if we add extra output for add when an empty file is passed but not the --empty flag?

Something like:

$ touch ~/.foo
$ chezmoi add ~/.foo
Do you really want to add an empty file? Use 'chezmoi add --empty $FILE'

Because while a documentation chage might help, I would rather have the program nudge me in the right direction.

@twpayne
Copy link
Owner

twpayne commented Jun 19, 2022

Hmmm, on reflection I think that chezmoi add not adding empty files is counter-intuitive behavior. #2161 makes chezmoi add add empty files (and adds the empty_ attribute if needed) and removes the --empty flag.

@twpayne twpayne added enhancement New feature or request and removed support Support request labels Jun 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants