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

Check dir supplied to copier exists before going through questions #1497

Closed
phinate opened this issue Feb 5, 2024 · 4 comments
Closed

Check dir supplied to copier exists before going through questions #1497

phinate opened this issue Feb 5, 2024 · 4 comments

Comments

@phinate
Copy link

phinate commented Feb 5, 2024

Actual Situation

One may accidentally run a copier copy command without making a new directory first if that's desired.

Desired Situation

I'd want the dir to be created for me, or an error message that comes up telling me the dir doesn't exist before filling in the template.

Proposed solution

Should be a pretty simple check to make, happy to open a PR for this.

Couldn't find this issue documented anywhere, so apologies if this is already supported with a flag or asked elsewhere.

edit: after playing around, I can see that the creation behavior is what happens (but errored on a particular string if the directory is read-only, e.g. /path/to/dir). Happy to close this, but I'd probably like it documented somewhere fairly early in the README that this is what happens!

@pawamoy
Copy link
Contributor

pawamoy commented Feb 5, 2024

That's pretty much implied by the first example:

copier copy path/to/project/template path/to/destination

I don't think adding troubleshooting notes early in the README is a good idea, but I'm not opposed to it either. Maybe Copier could instead output a useful error message when the destination directory is read-only.

@phinate
Copy link
Author

phinate commented Feb 5, 2024

+1 for the read-only error! You end up with a FileNotFoundError first if that directory doesn't exist.

regarding docs: I submitted some text in #1498 that I think should flag it minimally in the README, and a little more explicitly in the template generation page.

@yajo
Copy link
Member

yajo commented Feb 11, 2024

I don't think this is a good idea.

In case you run copy over a preexisting dir, copier will copy on it, just like it should do.

If the dir happens to be a git-tracked template that contains an answers file, you can use copy as a recopy alternative. Sometimes an upstream template lacks some patches, then you need to use a downstream template with those patches and you need to change the origin of the template. The only official way to do that is to issue a copy command over a preexisting template.

Let me close this request because it breaks expected behaviours, just to keep the issue tracker clean. But you can keep commenting if you want 😉

@yajo yajo closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2024
@pawamoy
Copy link
Contributor

pawamoy commented Feb 11, 2024

@yajo the suggestion was to handle the case where the destination directory already exists but is read-only, meaning Copier will never be able to write into it (be it for an update or a recopy). But after actually testing this out, it seems we already get a PermissionError, which is explicit enough I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants