This is handy when you trust .hgignore to specify all of your build
products, but you do not trust yourself to always remember to "hg add"
new files. This treats unknown files as valuable, since they might
become added files soon.
diff --git a/hgext/purge.py b/hgext/purge.py
--- a/hgext/purge.py
+++ b/hgext/purge.py
@@ -34,6 +34,7 @@
@command('purge|clean',
[('a', 'abort-on-err', None, _('abort if an error occurs')),
('', 'all', None, _('purge ignored files too')),
+ ('i', 'ignored-only', None, _('purge only ignored files (not unknown)')),
('p', 'print', None, _('print filenames instead of deleting them')),
('0', 'print0', None, _('end filenames with NUL, for use with xargs'
' (implies -p/--print)')),
@@ -45,7 +46,7 @@
Delete files not known to Mercurial. This is useful to test local
and uncommitted changes in an otherwise-clean source tree.
- This means that purge will delete:
+ By default, purge will delete:
- Unknown files: files marked with "?" by :hg:`status`
- Empty directories: in fact Mercurial ignores directories unless
@@ -57,6 +58,11 @@
- Ignored files (unless --all is specified)
- New files added to the repository (with :hg:`add`)
+ With `--all`, purge will remove both unknown and ignored files.
+
+ With `--ignored-only`, purge will instead remove only ignored
+ files, leaving unknown files alone.
+
If directories are given on the command line, only files in these
directories are considered.
@@ -97,7 +103,9 @@
directories = []
match = scmutil.match(repo[None], dirs, opts)
match.dir = directories.append
- status = repo.status(match=match, ignored=opts['all'], unknown=True)
+ ignored = (opts['all'] or opts['ignored_only'])
+ unknown = not opts['ignored_only']
+ status = repo.status(match=match, ignored=ignored, unknown=unknown)
for f in sorted(status[4] + status[5]):
ui.note(_('Removing file %s\n') % f)
diff --git a/tests/test-purge.t b/tests/test-purge.t
--- a/tests/test-purge.t
+++ b/tests/test-purge.t
@@ -136,6 +136,35 @@
directory
r1
+delete only ignored files
+ $ touch ignored untracked directory/untracked
+ $ hg purge -p --ignored-only
+ ignored
+ $ hg purge -v --ignored-only
+ Removing file ignored
+ $ ls
+ directory
+ r1
+ untracked
+ $ hg status -ui
+ ? directory/untracked
+ ? untracked
+
+delete only files in an ignored directory
+ $ mkdir ignored
+ $ touch ignored/stuff1 ignored/stuff2
+ $ hg purge -p -i
+ ignored/stuff1
+ ignored/stuff2
+ $ hg purge -v -i
+ Removing file ignored/stuff1
+ Removing file ignored/stuff2
+ Removing directory ignored
+ $ hg status -ui
+ ? directory/untracked
+ ? untracked
+ $ hg purge
+
abort with missing files until we support name mangling filesystems
$ touch untracked_file
_______________________________________________
Mercurial-devel mailing list
Mercuri...@selenic.com
http://selenic.com/mailman/listinfo/mercurial-devel
Does this work?
hg purge "set:ignored()"
If so, can we add this as an example for "hg help purge -v" instead?
I'm trying to prevent a combinatoric explosion of command-specific
options by adding general-purpose features like revsets and filesets.
--
Mathematics is the supreme nostalgia of our time.
-i is a terrible short name as it sound like "--interactive" an option that
some people would expect to ask confirmation before removing files (as `rm -i`
do)
I met such user yesterday.
--
Pierre-Yves David
Good point. Kinda like "hg strip -n" is not a dry run.
I'll drop the short option when (if) I resend.
Greg
--
Greg Ward http://www.gerg.ca/
"What do you mean -- a European or an African swallow?"
On 21 March 2012, Matt Mackall said:On Tue, 2012-03-20 at 21:50 -0400, Greg Ward wrote:# HG changeset patch# User Greg Ward <gr...@gerg.ca># Date 1332294424 14400# Node ID bfde5bbbc3bb0d804a70cad737f0bf95086a448c# Parent 12e3f93b1cbc7c930e941f0adfe632c8ad70b73dpurge: add --ignored-only/-i option to delete only ignored filesThis is handy when you trust .hgignore to specify all of your buildproducts, but you do not trust yourself to always remember to "hg add"new files. This treats unknown files as valuable, since they mightbecome added files soon.Does this work?hg purge "set:ignored()"
No, but
hg purge --all "set:ignored()"
does. purge only considers ignored files with --all.
Also, this does not remove empty directories.
However, this totally fails the usability test. I can just see me
trying to explain to one of my co-workers how to clean up a messy
working dir.
Ignored files may also be valuable. Config files are a common example of
things you never want to commit, but that you don't want Mercurial to
clobber. I think maybe half of projects have one or more of these.
> > Does this work?
> >
> > hg purge "set:ignored()"
>
> No, but
>
> hg purge --all "set:ignored()"
Hmm, perhaps we should fix that.
> Also, this does not remove empty directories.
Seems buggy.
> However, this totally fails the usability test. I can just see me
> trying to explain to one of my co-workers how to clean up a messy
> working dir.
The easy/safe way, of course, is 'hg clone'.