Mercurial > hg
comparison mercurial/commands.py @ 8902:b9a8b616521d
Add a forget command for easily untracking files.
This command does exactly what 'hg remove -Af [FILES]' does.
The reason for creating a new command is that the options for 'hg remove'
are confusing (-A removes only deleted files, -f forces deletion, and using
both means *the exact opposite of both*).
[mpm: simplified help text, code, and updated tests]
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Sun, 31 May 2009 03:09:00 -0400 |
parents | d0a3eadfbdb3 |
children | d403cf4eb32d |
comparison
equal
deleted
inserted
replaced
8901:94319ae527cf | 8902:b9a8b616521d |
---|---|
22 | 22 |
23 Schedule files to be version controlled and added to the | 23 Schedule files to be version controlled and added to the |
24 repository. | 24 repository. |
25 | 25 |
26 The files will be added to the repository at the next commit. To | 26 The files will be added to the repository at the next commit. To |
27 undo an add before that, see hg revert. | 27 undo an add before that, see hg forget. |
28 | 28 |
29 If no names are given, add all files to the repository. | 29 If no names are given, add all files to the repository. |
30 """ | 30 """ |
31 | 31 |
32 bad = [] | 32 bad = [] |
1135 else: | 1135 else: |
1136 ui.note(_('exporting patch:\n')) | 1136 ui.note(_('exporting patch:\n')) |
1137 patch.export(repo, revs, template=opts.get('output'), | 1137 patch.export(repo, revs, template=opts.get('output'), |
1138 switch_parent=opts.get('switch_parent'), | 1138 switch_parent=opts.get('switch_parent'), |
1139 opts=patch.diffopts(ui, opts)) | 1139 opts=patch.diffopts(ui, opts)) |
1140 | |
1141 def forget(ui, repo, *pats, **opts): | |
1142 """forget the specified files on the next commit | |
1143 | |
1144 Mark the specified files so they will no longer be tracked | |
1145 after the next commit. | |
1146 | |
1147 This only removes files from the current branch, not from the | |
1148 entire project history, and it does not delete them from the | |
1149 working directory. | |
1150 | |
1151 To undo a forget before the next commit, see hg add. | |
1152 """ | |
1153 | |
1154 if not pats: | |
1155 raise util.Abort(_('no files specified')) | |
1156 | |
1157 m = cmdutil.match(repo, pats, opts) | |
1158 s = repo.status(match=m, clean=True) | |
1159 forget = sorted(s[0] + s[1] + s[3] + s[6]) | |
1160 | |
1161 for f in m.files(): | |
1162 if f not in repo.dirstate and not os.path.isdir(m.rel(f)): | |
1163 ui.warn(_('not removing %s: file is already untracked\n') | |
1164 % m.rel(f)) | |
1165 | |
1166 for f in forget: | |
1167 if ui.verbose or not m.exact(f): | |
1168 ui.status(_('removing %s\n') % m.rel(f)) | |
1169 | |
1170 repo.remove(forget, unlink=False) | |
1140 | 1171 |
1141 def grep(ui, repo, pattern, *pats, **opts): | 1172 def grep(ui, repo, pattern, *pats, **opts): |
1142 """search for a pattern in specified files and revisions | 1173 """search for a pattern in specified files and revisions |
1143 | 1174 |
1144 Search revisions of files for a regular expression. | 1175 Search revisions of files for a regular expression. |
3267 (export, | 3298 (export, |
3268 [('o', 'output', '', _('print output to file with formatted name')), | 3299 [('o', 'output', '', _('print output to file with formatted name')), |
3269 ('', 'switch-parent', None, _('diff against the second parent')) | 3300 ('', 'switch-parent', None, _('diff against the second parent')) |
3270 ] + diffopts, | 3301 ] + diffopts, |
3271 _('[OPTION]... [-o OUTFILESPEC] REV...')), | 3302 _('[OPTION]... [-o OUTFILESPEC] REV...')), |
3303 "^forget": | |
3304 (forget, | |
3305 [] + walkopts, | |
3306 _('[OPTION]... FILE...')), | |
3272 "grep": | 3307 "grep": |
3273 (grep, | 3308 (grep, |
3274 [('0', 'print0', None, _('end fields with NUL')), | 3309 [('0', 'print0', None, _('end fields with NUL')), |
3275 ('', 'all', None, _('print all revisions that match')), | 3310 ('', 'all', None, _('print all revisions that match')), |
3276 ('f', 'follow', None, | 3311 ('f', 'follow', None, |