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

clean should not remove .git metadata #574

Closed
msoulier opened this issue Nov 5, 2012 · 11 comments
Closed

clean should not remove .git metadata #574

msoulier opened this issue Nov 5, 2012 · 11 comments
Assignees
Milestone

Comments

@msoulier
Copy link

msoulier commented Nov 5, 2012

I am deploying my pelican-generated site via heroku, so the target directory is a git repository. make clean deletes everything at the output directory, so I had to hack up my makefile to stop that behaviour.

@amanjeev
Copy link

@msoulier Can you share your solution please (or point me to the source)?

@rupert
Copy link

rupert commented Mar 24, 2013

@amanjeev

clean:
    find $(OUTPUTDIR) -mindepth 1 -name '.git*' -prune -o -delete

This will also exclude .gitignore, .gitconfig etc.

@justinmayer
Copy link
Member

@rupert: In my testing, those parameters to find preserves the .git directory itself but nukes everything inside it.

@rupert
Copy link

rupert commented Mar 25, 2013

Ah sorry, I've updated the find command above.

$ find output
output
output/.git
output/.git/hello
output/.gitignore
output/foo
output/foo/bar
output/hello
$ find output -mindepth 1 -name '.git*' -prune -o -print
output/foo
output/foo/bar
output/hello

@justinmayer
Copy link
Member

Great. Any idea as to the full command to delete everything but the .git directory and its contents?

@rupert
Copy link

rupert commented Mar 25, 2013

Delete everything except .git:

$ find $(OUTPUTDIR) -mindepth 1 -name .git -prune -o -delete

Delete everything except .git, .gitignore etc:

$ find $(OUTPUTDIR) -mindepth 1 -name '.git*' -prune -o -delete

@justinmayer
Copy link
Member

In my testing, those commands do the same as I noted previously: preserves the .git directory itself but nukes everything inside it.

@rupert
Copy link

rupert commented Mar 25, 2013

I wrote the commands for Mac OS X find. I've since found that the GNU version of find doesn't support using -prune with -delete.

@justinmayer, can you try:

$ find $(OUTPUTDIR) -mindepth 1 -name '.git*' -prune -o -print0 | xargs -0 rm -rf
$ find output
output
output/.git
output/.git/hello
output/.gitignore
output/foo
output/foo/bar
output/hello
$ make clean
find /Users/rupert/rupertb.com/output -mindepth 1 -name '.git*' -prune -o -print0 | xargs -0 rm -rf
$ find output
output
output/.git
output/.git/hello
output/.gitignore

@justinmayer
Copy link
Member

I actually did my testing on Mac OS X 10.8.2 to produce the behavior described above.

I thought about xargs, but once we get to the point of piping things to rm -rf, I think we've crossed the line over into... a potentially bad place. ;^)

Honestly, if folks want to avoid nuking .git, .hg, and other files/directories in the output folder, they are probably better off installing and using ack instead of wrangling with find. Perhaps someone would care to write up an appropriate line for the Makefile using ack and then add it to our Tips page?

@justinmayer
Copy link
Member

Instead of the Makefile, I believe that output folder cleaning behavior should, whenever possible, be handled by pelican.util's clean_output_dir function and the DELETE_OUTPUT_DIRECTORY setting. To that end, I've proposed a solution to this problem via PR #944. Comments and suggestions are welcome.

justinmayer added a commit to justinmayer/pelican that referenced this issue Jun 24, 2013
If DELETE_OUTPUT_DIRECTORY is set to True, all files and directories are
deleted from the output directory. There are, however, several reasons
one might want to retain certain files/directories and avoid their
deletion from the output directory. One such use case is version control
system data: a versioned output directory can facilitate deployment via
Heroku and/or allow the user to easily revert to a prior version of the
site without having to rely on regeneration via Pelican.

This change introduces the OUTPUT_RETENTION setting, a tuple of
filenames that will be preserved when the clean_output_dir function in
pelican.utils is run. Setting OUTPUT_RETENTION = (".hg", ".git") would,
for example, prevent the relevant VCS data from being deleted when the
output directory is cleaned.
@justinmayer
Copy link
Member

I've introduced the OUTPUT_RETENTION setting to address this use case. I hope folks find it to be useful.

justinmayer added a commit that referenced this issue Jun 26, 2013
Keep certain files when cleaning output; fix #574
bport pushed a commit to bport/pelican that referenced this issue Apr 1, 2014
If DELETE_OUTPUT_DIRECTORY is set to True, all files and directories are
deleted from the output directory. There are, however, several reasons
one might want to retain certain files/directories and avoid their
deletion from the output directory. One such use case is version control
system data: a versioned output directory can facilitate deployment via
Heroku and/or allow the user to easily revert to a prior version of the
site without having to rely on regeneration via Pelican.

This change introduces the OUTPUT_RETENTION setting, a tuple of
filenames that will be preserved when the clean_output_dir function in
pelican.utils is run. Setting OUTPUT_RETENTION = (".hg", ".git") would,
for example, prevent the relevant VCS data from being deleted when the
output directory is cleaned.
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

4 participants