Skip to content

Fixed the override not working with copy only dir #1650#1651

Merged
insspb merged 5 commits intocookiecutter:masterfrom
zhongdai:fixed-override-option-with-copy-only-dir
Jun 6, 2022
Merged

Fixed the override not working with copy only dir #1650#1651
insspb merged 5 commits intocookiecutter:masterfrom
zhongdai:fixed-override-option-with-copy-only-dir

Conversation

@zhongdai
Copy link
Copy Markdown
Contributor

@zhongdai zhongdai commented Mar 2, 2022

Fixed the issue of failure execution when

  • the overwrite_if_exists=True
  • there are copy only directories in the context

@zhongdai
Copy link
Copy Markdown
Contributor Author

This bug is really annoying when you create your own cookiecutter package and need to generate the files again and again. You have to manual rm -rf the-dir before you can re-generate it. Is there anyone who can have a look?

@att14
Copy link
Copy Markdown
Contributor

att14 commented Apr 11, 2022

Here was my attempt to fix the failing test: 19a8f2f.

It might not work on Windows, though.

@zhongdai
Copy link
Copy Markdown
Contributor Author

@att14

Let step back to think about the requirement of this -f flag. I had a look for the document, and I noticed doc. It says Overwrite the contents of the output directory if it already exists.

Here is my understanding, if you decide to use -f flag, you give up any changes to the existing clone, and you re-start a new clone. So my initial fix was straightforward, deleting the existing clone.

The -f is not a frequently used option, because most of the time, you clone once, and you start to modify the clone. However, this flag is useful for template developers, they need to clone the template again and again to check the output content. During the testing/verification, they don't want to pick different project names, so the -f flag is very handy to let them use the same project name.

I am happy to hear your thought or anyone else from the committer group.

@att14
Copy link
Copy Markdown
Contributor

att14 commented Apr 12, 2022

I don't disagree with you. I'm confused what the problem is. The change I made is to make your delete respect the -f option. You want to avoid deleting all the copy only directories if they haven't supplied -f.

@zhongdai
Copy link
Copy Markdown
Contributor Author

I don't think there is a case the copy-on-dir exists and the overwrite_if_exists=False. Please check this block of code, if the cloned dir exists and the overwrite_if_exists=False, the program will raise an exception, but not copying/rendering anything. This means, if the code hits this line if os.path.isdir(outdir) and overwrite_if_exists:, the overwrite_if_exists must be True, and we don't need to add that check.

I also noticed there is any flag skip_if_file_exists, and I believe that is the one to control not overriding any modified content.

@att14
Copy link
Copy Markdown
Contributor

att14 commented Apr 13, 2022

You are correct, but I see no reason to avoid being defensive since the check is in another function.

@insspb insspb force-pushed the fixed-override-option-with-copy-only-dir branch from 16965c9 to 418e316 Compare June 6, 2022 08:24
@insspb
Copy link
Copy Markdown
Member

insspb commented Jun 6, 2022

@zhongdai @att14 thank you for contribution. Rebased and merged.

@insspb insspb merged commit e07a2a8 into cookiecutter:master Jun 6, 2022
@insspb insspb added the bug This issue/PR relates to a bug. label Jun 6, 2022
@insspb insspb changed the title fixed the override not working with copy only dir #1650 Fixed the override not working with copy only dir #1650 Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants