31 self._ui = None |
31 self._ui = None |
32 self._hg_root = None |
32 self._hg_root = None |
33 self._act = act |
33 self._act = act |
34 self._abort_on_err = abort_on_err |
34 self._abort_on_err = abort_on_err |
35 |
35 |
36 def purge(self, ui, repo, paths=None): |
36 def purge(self, ui, repo, dirs=None): |
37 self._repo = repo |
37 self._repo = repo |
38 self._ui = ui |
38 self._ui = ui |
39 self._hg_root = self._split_path(repo.root) |
39 self._hg_root = self._split_path(repo.root) |
40 |
40 |
41 if not paths: |
41 if not dirs: |
42 paths = [repo.root] |
42 dirs = [repo.root] |
43 |
43 |
44 for path in paths: |
44 for path in dirs: |
45 path = os.path.abspath(path) |
45 path = os.path.abspath(path) |
46 for root, dirs, files in os.walk(path, topdown=False): |
46 for root, dirs, files in os.walk(path, topdown=False): |
47 if '.hg' in self._split_path(root): |
47 if '.hg' in self._split_path(root): |
48 # Skip files in the .hg directory. |
48 # Skip files in the .hg directory. |
49 # Note that if the repository is in a directory |
49 # Note that if the repository is in a directory |
127 else: |
127 else: |
128 ret = part |
128 ret = part |
129 return ret |
129 return ret |
130 |
130 |
131 |
131 |
132 def purge(ui, repo, *paths, **opts): |
132 def purge(ui, repo, *dirs, **opts): |
133 '''removes files not tracked by mercurial |
133 '''removes files not tracked by mercurial |
134 |
134 |
135 Delete files not known to mercurial, this is useful to test local and |
135 Delete files not known to mercurial, this is useful to test local and |
136 uncommitted changes in the otherwise clean source tree. |
136 uncommitted changes in the otherwise clean source tree. |
137 |
137 |
138 This means that purge will delete: |
138 This means that purge will delete: |
139 - Unknown files: files marked with "?" by "hg status" |
139 - Unknown files: files marked with "?" by "hg status" |
140 - Ignored files: files usually ignored by Mercurial because they match a |
140 - Ignored files: files usually ignored by Mercurial because they match |
141 pattern in a ".hgignore" file |
141 a pattern in a ".hgignore" file |
142 - Empty directories: infact Mercurial ignores directories unless they |
142 - Empty directories: infact Mercurial ignores directories unless they |
143 contain files under source control managment |
143 contain files under source control managment |
144 But it will leave untouched: |
144 But it will leave untouched: |
145 - Unmodified tracked files |
145 - Unmodified tracked files |
146 - Modified tracked files |
146 - Modified tracked files |
147 - New files added to the repository (with "hg add") |
147 - New files added to the repository (with "hg add") |
148 |
148 |
149 If names are given, only files matching the names are considered, else |
149 If directories are given on the command line, only files in these |
150 all files in the repository directory are considered. |
150 directories are considered. |
151 |
151 |
152 Be careful with purge, you could irreversibly delete some files you |
152 Be careful with purge, you could irreversibly delete some files you |
153 forgot to add to the repository. If you only want to print the list of |
153 forgot to add to the repository. If you only want to print the list of |
154 files that this program would delete use the -vn options. |
154 files that this program would delete use the -vn options. |
155 ''' |
155 ''' |
156 act = not opts['nothing'] |
156 act = not opts['nothing'] |
157 abort_on_err = bool(opts['abort_on_err']) |
157 abort_on_err = bool(opts['abort_on_err']) |
158 p = Purge(act, abort_on_err) |
158 p = Purge(act, abort_on_err) |
159 p.purge(ui, repo, paths) |
159 p.purge(ui, repo, dirs) |
160 |
160 |
161 |
161 |
162 cmdtable = { |
162 cmdtable = { |
163 'purge': (purge, |
163 'purge': (purge, |
164 [('a', 'abort-on-err', None, _('abort if an error occurs')), |
164 [('a', 'abort-on-err', None, _('abort if an error occurs')), |
165 ('n', 'nothing', None, _('do nothing on files, useful with --verbose')), |
165 ('n', 'nothing', None, _('do nothing on files, useful with --verbose')), |
166 ], |
166 ], |
167 _('hg purge [OPTIONS] [NAME]')) |
167 _('hg purge [OPTIONS] [DIR]')) |
168 } |
168 } |