diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -24,7 +24,7 @@ def add(ui, repo, *pats, **opts): 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 @@ def export(ui, repo, *changesets, **opts 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 @@ table = { ('', '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 --git a/tests/test-add b/tests/test-add --- a/tests/test-add +++ b/tests/test-add @@ -7,6 +7,9 @@ hg add -n 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 resolve -m a hg ci -m merge echo % issue683 +hg forget a +hg add a +hg st hg rm a hg st echo a > a diff --git a/tests/test-add.out b/tests/test-add.out --- a/tests/test-add.out +++ b/tests/test-add.out @@ -2,6 +2,8 @@ adding a ? a adding a A a +adding a +A a A a ? b A a @@ -26,6 +28,7 @@ a already tracked! M a ? a.orig % issue683 +? a.orig R a ? a.orig M a diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out --- a/tests/test-debugcomplete.out +++ b/tests/test-debugcomplete.out @@ -14,6 +14,7 @@ commit copy diff export +forget grep heads help @@ -167,6 +168,7 @@ clone: noupdate, rev, pull, uncompressed 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 --git a/tests/test-globalopts.out b/tests/test-globalopts.out --- a/tests/test-globalopts.out +++ b/tests/test-globalopts.out @@ -164,6 +164,7 @@ list of commands: 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 @@ list of commands: 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 --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -8,6 +8,7 @@ basic commands: 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 @@ use "hg help" for the full list of comma 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 @@ list of commands: 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 @@ use "hg -v help" to show aliases and glo 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 @@ add the specified files on the next comm 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 @@ add the specified files on the next comm 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 @@ basic commands: 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 @@ basic commands: 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 --git a/tests/test-qrecord.out b/tests/test-qrecord.out --- a/tests/test-qrecord.out +++ b/tests/test-qrecord.out @@ -10,6 +10,7 @@ basic commands: 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 --git a/tests/test-strict.out b/tests/test-strict.out --- a/tests/test-strict.out +++ b/tests/test-strict.out @@ -11,6 +11,7 @@ basic commands: 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