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

Don't checkout anything by default on local templates #184

Closed
pawamoy opened this issue Apr 16, 2020 · 11 comments · Fixed by #520
Closed

Don't checkout anything by default on local templates #184

pawamoy opened this issue Apr 16, 2020 · 11 comments · Fixed by #520
Labels
help wanted The issue is valid, but we need community contributions to fix it

Comments

@pawamoy
Copy link
Contributor

pawamoy commented Apr 16, 2020

I'm currently translating a cookiecutter template to a copier one, and each time I change something, I have to commit the change for copier to pick it up. At first it was confusing ("why did files that I removed were copied??"), and now it's annoying (a "wip" commit for every change, and then I'll have to squash them or something).

I think it's because copier tries to checkout the latest tag? I'd like it not to do anything if I don't specify the -r, --vcs-ref option.

@yajo
Copy link
Member

yajo commented Apr 20, 2020

This is important because copier uses git tags to handle upgrades. Also, copier needs a ref to be saved into the _commit key in .copier-answers.yml.

However, I agree this is a little pain point for template development.

One thing I do is:

  1. Commit your changes.
  2. Add --vcs-ref=HEAD to your copy command.

For unit tests, however, I simply use this pytest fixture, which clones the current template into a temporary directory, including dirty changes, applies a test tag (so I know .copier-answers.yml will always have _commit: test) and returns the Path to that clone, which can be safely used in TDD.

Copier could include a --vcs flag with these options: auto, git, none. It should default to auto (use git if available, none otherwise), but this way users could just give --vcs=none and skip all the gitty stuff.

@pawamoy
Copy link
Contributor Author

pawamoy commented Apr 20, 2020

Copier could include a --vcs flag with these options: auto, git, none. It should default to auto (use git if available, none otherwise), but this way users could just give --vcs=none and skip all the gitty stuff.

That would be great 🙂

I totally get why the checkouts are important for being able to update the generated projects, though if users could disable it it could really facilitate the development!

@pawamoy
Copy link
Contributor Author

pawamoy commented Apr 29, 2020

It's especially annoying when you have tests for your template: you must commit before running the tests 🤣 !

@yajo
Copy link
Member

yajo commented Apr 30, 2020

Not with that fixture provided above. Although you're right this should be fixed.

@pawamoy
Copy link
Contributor Author

pawamoy commented Apr 30, 2020

Oh yes, thank you! I happen to have written my tests in a simple shell script though 😅

But I'll use your fixture if I convert them to a pytest suite.

@yajo
Copy link
Member

yajo commented Apr 30, 2020

You can also emulate that fixture as a bash function, it's quite easy.

@yajo
Copy link
Member

yajo commented Sep 26, 2020

I'm thinking that a good fix might be to supply that fixture with Copier, so downstream templates can reuse it.

@dennisroche
Copy link
Contributor

dennisroche commented Jun 15, 2021

As suggested in #412, could we make these two commands behave differently?

copier . ./tmp

use the local changes instead of the git repo if template_src is not a url

copier copy https://github.com/copier-org/autopretty.git .?

as-is

If that isn't possible (or what you prefer) then perhaps a flag --local or --no-git to change the behavior.

As a user I want to be able to test templates quickly/iteratively using existing cli tool (not via pytest fixture)

@yajo
Copy link
Member

yajo commented Jun 15, 2021

As a user I want to be able to test templates quickly/iteratively using existing cli tool (not via pytest fixture)

Yes, well that makes sense indeed.

However, I cannot predict what you want to test. Is it a copy, a recopy or an update? Besides, when copying a non-git template, the results and features are different, so you could get to unexpected results when comparing your dev with production environments.

However I guess that we can make this assumption: if the template is a local directory and it is dirty, you're developing the template, so you're going to want to test those dirty changes, so Copier could take the freedom to do the wip commit dance automatically and print a warning so you are aware of that.

@hojerst
Copy link

hojerst commented Nov 12, 2021

I'd also really like to see this feature in some kind.
Just some ideas which would simplify local testing during development:

  • add a flag like --vcs-ref=dirty or something like that. (semantic: if it is a local git repo, just add -dirty to the commit-hash for the answer file and use the dirty, checked out version)
  • use --vcs-ref=none to disable the git tag stuff completely. IMHO this is completely sufficient for a quick test. Even if the result might differ slightly from a git repository. You could also print a warning about the caveats.

This should only be relevant during development of templates. Depending on your workflow there is still the option to run a commit as soon as you assume you are finshed and run a "real life test with git" before publishing.

@yajo
Copy link
Member

yajo commented Nov 14, 2021

Those are OK until somebody creates a branch named dirty or none. 😄

I think I still prefer the suggestion from #184 (comment).

@yajo yajo added the help wanted The issue is valid, but we need community contributions to fix it label Nov 20, 2021
@yajo yajo linked a pull request Jan 11, 2022 that will close this issue
@yajo yajo closed this as completed in #520 Jan 11, 2022
yajo pushed a commit that referenced this issue Jan 11, 2022
- if a template is vcs-tracked and dirty, the changes are committed automatically with a "wip" commit and propagated to the subproject
- user is warned in this scenario
- tests for copy and update on dirty templates

fixes #184
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted The issue is valid, but we need community contributions to fix it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants