# HG changeset patch # User Steve Losh # Date 1243753740 14400 # Node ID b9a8b616521dfb742478410351d3387b0ce975cb # Parent 94319ae527cf783e3a75ab2a1ea322d2e17ceae7 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] diff -r 94319ae527cf -r b9a8b616521d mercurial/commands.py --- a/mercurial/commands.py Sun Jun 21 03:11:52 2009 +0200 +++ b/mercurial/commands.py Sun May 31 03:09:00 2009 -0400 @@ -24,7 +24,7 @@ repository. The files will be added to the repository at the next commit. To - undo an add before that, see hg revert. + undo an add before that, see hg forget. If no names are given, add all files to the repository. """ @@ -1138,6 +1138,37 @@ switch_parent=opts.get('switch_parent'), opts=patch.diffopts(ui, opts)) +def forget(ui, repo, *pats, **opts): + """forget the specified files on the next commit + + Mark the specified files so they will no longer be tracked + after the next commit. + + This only removes files from the current branch, not from the + entire project history, and it does not delete them from the + working directory. + + To undo a forget before the next commit, see hg add. + """ + + if not pats: + raise util.Abort(_('no files specified')) + + m = cmdutil.match(repo, pats, opts) + s = repo.status(match=m, clean=True) + forget = sorted(s[0] + s[1] + s[3] + s[6]) + + for f in m.files(): + if f not in repo.dirstate and not os.path.isdir(m.rel(f)): + ui.warn(_('not removing %s: file is already untracked\n') + % m.rel(f)) + + for f in forget: + if ui.verbose or not m.exact(f): + ui.status(_('removing %s\n') % m.rel(f)) + + repo.remove(forget, unlink=False) + def grep(ui, repo, pattern, *pats, **opts): """search for a pattern in specified files and revisions @@ -3269,6 +3300,10 @@ ('', 'switch-parent', None, _('diff against the second parent')) ] + diffopts, _('[OPTION]... [-o OUTFILESPEC] REV...')), + "^forget": + (forget, + [] + walkopts, + _('[OPTION]... FILE...')), "grep": (grep, [('0', 'print0', None, _('end fields with NUL')), diff -r 94319ae527cf -r b9a8b616521d tests/test-add --- a/tests/test-add Sun Jun 21 03:11:52 2009 +0200 +++ b/tests/test-add Sun May 31 03:09:00 2009 -0400 @@ -7,6 +7,9 @@ hg st hg add hg st +hg forget a +hg add +hg st echo b > b hg add -n b @@ -36,6 +39,9 @@ hg ci -m merge echo % issue683 +hg forget a +hg add a +hg st hg rm a hg st echo a > a diff -r 94319ae527cf -r b9a8b616521d tests/test-add.out --- a/tests/test-add.out Sun Jun 21 03:11:52 2009 +0200 +++ b/tests/test-add.out Sun May 31 03:09:00 2009 -0400 @@ -2,6 +2,8 @@ ? a adding a A a +adding a +A a A a ? b A a @@ -26,6 +28,7 @@ M a ? a.orig % issue683 +? a.orig R a ? a.orig M a diff -r 94319ae527cf -r b9a8b616521d tests/test-debugcomplete.out --- a/tests/test-debugcomplete.out Sun Jun 21 03:11:52 2009 +0200 +++ b/tests/test-debugcomplete.out Sun May 31 03:09:00 2009 -0400 @@ -14,6 +14,7 @@ copy diff export +forget grep heads help @@ -167,6 +168,7 @@ commit: addremove, close-branch, include, exclude, message, logfile, date, user diff: rev, change, text, git, nodates, show-function, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, include, exclude export: output, switch-parent, text, git, nodates +forget: include, exclude init: ssh, remotecmd log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, prune, patch, git, limit, no-merges, style, template, include, exclude merge: force, rev, preview diff -r 94319ae527cf -r b9a8b616521d tests/test-globalopts.out --- a/tests/test-globalopts.out Sun Jun 21 03:11:52 2009 +0200 +++ b/tests/test-globalopts.out Sun May 31 03:09:00 2009 -0400 @@ -164,6 +164,7 @@ copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit grep search for a pattern in specified files and revisions heads show current repository heads or show branch heads help show help for a given topic or a help overview @@ -230,6 +231,7 @@ copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit grep search for a pattern in specified files and revisions heads show current repository heads or show branch heads help show help for a given topic or a help overview diff -r 94319ae527cf -r b9a8b616521d tests/test-help.out --- a/tests/test-help.out Sun Jun 21 03:11:52 2009 +0200 +++ b/tests/test-help.out Sun May 31 03:09:00 2009 -0400 @@ -8,6 +8,7 @@ commit commit the specified files or all outstanding changes diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit init create a new repository in the given directory log show revision history of entire repository or files merge merge working directory with another revision @@ -26,6 +27,7 @@ commit commit the specified files or all outstanding changes diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit init create a new repository in the given directory log show revision history of entire repository or files merge merge working directory with another revision @@ -55,6 +57,7 @@ copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit grep search for a pattern in specified files and revisions heads show current repository heads or show branch heads help show help for a given topic or a help overview @@ -117,6 +120,7 @@ copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit grep search for a pattern in specified files and revisions heads show current repository heads or show branch heads help show help for a given topic or a help overview @@ -170,7 +174,7 @@ repository. The files will be added to the repository at the next commit. To - undo an add before that, see hg revert. + undo an add before that, see hg forget. If no names are given, add all files to the repository. @@ -190,7 +194,7 @@ repository. The files will be added to the repository at the next commit. To - undo an add before that, see hg revert. + undo an add before that, see hg forget. If no names are given, add all files to the repository. @@ -309,6 +313,7 @@ commit commit the specified files or all outstanding changes diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit init create a new repository in the given directory log show revision history of entire repository or files merge merge working directory with another revision @@ -332,6 +337,7 @@ commit commit the specified files or all outstanding changes diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit init create a new repository in the given directory log show revision history of entire repository or files merge merge working directory with another revision diff -r 94319ae527cf -r b9a8b616521d tests/test-qrecord.out --- a/tests/test-qrecord.out Sun Jun 21 03:11:52 2009 +0200 +++ b/tests/test-qrecord.out Sun May 31 03:09:00 2009 -0400 @@ -10,6 +10,7 @@ commit commit the specified files or all outstanding changes diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit init create a new repository in the given directory log show revision history of entire repository or files merge merge working directory with another revision diff -r 94319ae527cf -r b9a8b616521d tests/test-strict.out --- a/tests/test-strict.out Sun Jun 21 03:11:52 2009 +0200 +++ b/tests/test-strict.out Sun May 31 03:09:00 2009 -0400 @@ -11,6 +11,7 @@ commit commit the specified files or all outstanding changes diff diff repository (or selected files) export dump the header and diffs for one or more changesets + forget forget the specified files on the next commit init create a new repository in the given directory log show revision history of entire repository or files merge merge working directory with another revision