Mercurial > hg
changeset 23325:4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Like 'forget', git and svn subrepos are currently not supported. Unfortunately
the name 'remove' is already used in the subrepo classes, so we break the
convention of naming the subrepo function after the command.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 15 Nov 2014 21:36:19 -0500 |
parents | 69f86b937035 |
children | f6b8d23492e5 |
files | mercurial/cmdutil.py mercurial/commands.py mercurial/help/subrepos.txt mercurial/subrepo.py tests/test-completion.t tests/test-help.t tests/test-subrepo-deep-nested-change.t |
diffstat | 7 files changed, 69 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sat Nov 15 13:50:43 2014 +0900 +++ b/mercurial/cmdutil.py Sat Nov 15 21:36:19 2014 -0500 @@ -2052,21 +2052,44 @@ forgot.extend(forget) return bad, forgot -def remove(ui, repo, m, after, force): +def remove(ui, repo, m, prefix, after, force, subrepos): + join = lambda f: os.path.join(prefix, f) ret = 0 s = repo.status(match=m, clean=True) modified, added, deleted, clean = s[0], s[1], s[3], s[6] + wctx = repo[None] + + if subrepos: + for subpath in sorted(wctx.substate): + sub = wctx.sub(subpath) + try: + submatch = matchmod.narrowmatcher(subpath, m) + if sub.removefiles(ui, submatch, prefix, after, force, + subrepos): + ret = 1 + except error.LookupError: + ui.status(_("skipping missing subrepository: %s\n") + % join(subpath)) + # warn about failure to delete explicit files/dirs - wctx = repo[None] for f in m.files(): - if f in repo.dirstate or f in wctx.dirs(): + def insubrepo(): + for subpath in wctx.substate: + if f.startswith(subpath): + return True + return False + + if f in repo.dirstate or f in wctx.dirs() or (subrepos and insubrepo()): continue - if os.path.exists(m.rel(f)): - if os.path.isdir(m.rel(f)): - ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) + + if os.path.exists(m.rel(join(f))): + if os.path.isdir(m.rel(join(f))): + ui.warn(_('not removing %s: no tracked files\n') + % m.rel(join(f))) else: - ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) + ui.warn(_('not removing %s: file is untracked\n') + % m.rel(join(f))) # missing files will generate a warning elsewhere ret = 1 @@ -2075,22 +2098,22 @@ elif after: list = deleted for f in modified + added + clean: - ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) + ui.warn(_('not removing %s: file still exists\n') % m.rel(join(f))) ret = 1 else: list = deleted + clean for f in modified: ui.warn(_('not removing %s: file is modified (use -f' - ' to force removal)\n') % m.rel(f)) + ' to force removal)\n') % m.rel(join(f))) ret = 1 for f in added: ui.warn(_('not removing %s: file has been marked for add' - ' (use forget to undo)\n') % m.rel(f)) + ' (use forget to undo)\n') % m.rel(join(f))) ret = 1 for f in sorted(list): if ui.verbose or not m.exact(f): - ui.status(_('removing %s\n') % m.rel(f)) + ui.status(_('removing %s\n') % m.rel(join(f))) wlock = repo.wlock() try:
--- a/mercurial/commands.py Sat Nov 15 13:50:43 2014 +0900 +++ b/mercurial/commands.py Sat Nov 15 21:36:19 2014 -0500 @@ -5086,7 +5086,7 @@ [('A', 'after', None, _('record delete for missing files')), ('f', 'force', None, _('remove (and delete) file even if added or modified')), - ] + walkopts, + ] + subrepoopts + walkopts, _('[OPTION]... FILE...'), inferrepo=True) def remove(ui, repo, *pats, **opts): @@ -5131,7 +5131,8 @@ raise util.Abort(_('no files specified')) m = scmutil.match(repo[None], pats, opts) - return cmdutil.remove(ui, repo, m, after, force) + subrepos = opts.get('subrepos') + return cmdutil.remove(ui, repo, m, "", after, force, subrepos) @command('rename|move|mv', [('A', 'after', None, _('record a rename that has already occurred')),
--- a/mercurial/help/subrepos.txt Sat Nov 15 13:50:43 2014 +0900 +++ b/mercurial/help/subrepos.txt Sat Nov 15 21:36:19 2014 -0500 @@ -129,6 +129,10 @@ elements. Subversion subrepositories are currently silently ignored. +:remove: remove does not recurse into subrepositories unless + -S/--subrepos is specified. Git and Subversion subrepositories + are currently silently ignored. + :update: update restores the subrepos in the state they were originally committed in target changeset. If the recorded changeset is not available in the current subrepository, Mercurial
--- a/mercurial/subrepo.py Sat Nov 15 13:50:43 2014 +0900 +++ b/mercurial/subrepo.py Sat Nov 15 21:36:19 2014 -0500 @@ -501,6 +501,13 @@ def forget(self, ui, match, prefix): return ([], []) + def removefiles(self, ui, matcher, prefix, after, force, subrepos): + """remove the matched files from the subrepository and the filesystem, + possibly by force and/or after the file has been removed from the + filesystem. Return 0 on success, 1 on any warning. + """ + return 1 + def revert(self, ui, substate, *pats, **opts): ui.warn('%s: reverting %s subrepos is unsupported\n' \ % (substate[0], substate[2])) @@ -854,6 +861,12 @@ os.path.join(prefix, self._path), True) @annotatesubrepoerror + def removefiles(self, ui, matcher, prefix, after, force, subrepos): + return cmdutil.remove(ui, self._repo, matcher, + os.path.join(prefix, self._path), after, force, + subrepos) + + @annotatesubrepoerror def revert(self, ui, substate, *pats, **opts): # reverting a subrepo is a 2 step process: # 1. if the no_backup is not set, revert all modified
--- a/tests/test-completion.t Sat Nov 15 13:50:43 2014 +0900 +++ b/tests/test-completion.t Sat Nov 15 21:36:19 2014 -0500 @@ -210,7 +210,7 @@ merge: force, rev, preview, tool pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure push: force, rev, bookmark, branch, new-branch, ssh, remotecmd, insecure - remove: after, force, include, exclude + remove: after, force, subrepos, include, exclude serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, include, exclude, subrepos, template summary: remote
--- a/tests/test-help.t Sat Nov 15 13:50:43 2014 +0900 +++ b/tests/test-help.t Sat Nov 15 21:36:19 2014 -0500 @@ -1944,6 +1944,9 @@ <tr><td>-f</td> <td>--force</td> <td>remove (and delete) file even if added or modified</td></tr> + <tr><td>-S</td> + <td>--subrepos</td> + <td>recurse into subrepositories</td></tr> <tr><td>-I</td> <td>--include PATTERN [+]</td> <td>include names matching the given patterns</td></tr>
--- a/tests/test-subrepo-deep-nested-change.t Sat Nov 15 13:50:43 2014 +0900 +++ b/tests/test-subrepo-deep-nested-change.t Sat Nov 15 21:36:19 2014 -0500 @@ -110,6 +110,17 @@ $ hg ci -Sm "add test.txt" committing subrepository sub1 committing subrepository sub1/sub2 (glob) + +.. but first take a detour through some deep removal testing + + $ hg remove -S -I 're:.*.txt' sub1 + removing sub1/sub2/folder/test.txt (glob) + removing sub1/sub2/test.txt (glob) + $ hg status -S + R sub1/sub2/folder/test.txt + R sub1/sub2/test.txt + $ hg update -Cq + $ hg --config extensions.largefiles=! archive -S ../archive_all $ find ../archive_all | sort ../archive_all