Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 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 | ae5d0a22ee7e |
children | f6b8d23492e5 |
comparison
equal
deleted
inserted
replaced
23324:69f86b937035 | 23325:4165cfd67519 |
---|---|
2050 rejected = wctx.forget(forget, prefix) | 2050 rejected = wctx.forget(forget, prefix) |
2051 bad.extend(f for f in rejected if f in match.files()) | 2051 bad.extend(f for f in rejected if f in match.files()) |
2052 forgot.extend(forget) | 2052 forgot.extend(forget) |
2053 return bad, forgot | 2053 return bad, forgot |
2054 | 2054 |
2055 def remove(ui, repo, m, after, force): | 2055 def remove(ui, repo, m, prefix, after, force, subrepos): |
2056 join = lambda f: os.path.join(prefix, f) | |
2056 ret = 0 | 2057 ret = 0 |
2057 s = repo.status(match=m, clean=True) | 2058 s = repo.status(match=m, clean=True) |
2058 modified, added, deleted, clean = s[0], s[1], s[3], s[6] | 2059 modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
2059 | 2060 |
2061 wctx = repo[None] | |
2062 | |
2063 if subrepos: | |
2064 for subpath in sorted(wctx.substate): | |
2065 sub = wctx.sub(subpath) | |
2066 try: | |
2067 submatch = matchmod.narrowmatcher(subpath, m) | |
2068 if sub.removefiles(ui, submatch, prefix, after, force, | |
2069 subrepos): | |
2070 ret = 1 | |
2071 except error.LookupError: | |
2072 ui.status(_("skipping missing subrepository: %s\n") | |
2073 % join(subpath)) | |
2074 | |
2060 # warn about failure to delete explicit files/dirs | 2075 # warn about failure to delete explicit files/dirs |
2061 wctx = repo[None] | |
2062 for f in m.files(): | 2076 for f in m.files(): |
2063 if f in repo.dirstate or f in wctx.dirs(): | 2077 def insubrepo(): |
2078 for subpath in wctx.substate: | |
2079 if f.startswith(subpath): | |
2080 return True | |
2081 return False | |
2082 | |
2083 if f in repo.dirstate or f in wctx.dirs() or (subrepos and insubrepo()): | |
2064 continue | 2084 continue |
2065 if os.path.exists(m.rel(f)): | 2085 |
2066 if os.path.isdir(m.rel(f)): | 2086 if os.path.exists(m.rel(join(f))): |
2067 ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) | 2087 if os.path.isdir(m.rel(join(f))): |
2088 ui.warn(_('not removing %s: no tracked files\n') | |
2089 % m.rel(join(f))) | |
2068 else: | 2090 else: |
2069 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) | 2091 ui.warn(_('not removing %s: file is untracked\n') |
2092 % m.rel(join(f))) | |
2070 # missing files will generate a warning elsewhere | 2093 # missing files will generate a warning elsewhere |
2071 ret = 1 | 2094 ret = 1 |
2072 | 2095 |
2073 if force: | 2096 if force: |
2074 list = modified + deleted + clean + added | 2097 list = modified + deleted + clean + added |
2075 elif after: | 2098 elif after: |
2076 list = deleted | 2099 list = deleted |
2077 for f in modified + added + clean: | 2100 for f in modified + added + clean: |
2078 ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) | 2101 ui.warn(_('not removing %s: file still exists\n') % m.rel(join(f))) |
2079 ret = 1 | 2102 ret = 1 |
2080 else: | 2103 else: |
2081 list = deleted + clean | 2104 list = deleted + clean |
2082 for f in modified: | 2105 for f in modified: |
2083 ui.warn(_('not removing %s: file is modified (use -f' | 2106 ui.warn(_('not removing %s: file is modified (use -f' |
2084 ' to force removal)\n') % m.rel(f)) | 2107 ' to force removal)\n') % m.rel(join(f))) |
2085 ret = 1 | 2108 ret = 1 |
2086 for f in added: | 2109 for f in added: |
2087 ui.warn(_('not removing %s: file has been marked for add' | 2110 ui.warn(_('not removing %s: file has been marked for add' |
2088 ' (use forget to undo)\n') % m.rel(f)) | 2111 ' (use forget to undo)\n') % m.rel(join(f))) |
2089 ret = 1 | 2112 ret = 1 |
2090 | 2113 |
2091 for f in sorted(list): | 2114 for f in sorted(list): |
2092 if ui.verbose or not m.exact(f): | 2115 if ui.verbose or not m.exact(f): |
2093 ui.status(_('removing %s\n') % m.rel(f)) | 2116 ui.status(_('removing %s\n') % m.rel(join(f))) |
2094 | 2117 |
2095 wlock = repo.wlock() | 2118 wlock = repo.wlock() |
2096 try: | 2119 try: |
2097 if not after: | 2120 if not after: |
2098 for f in list: | 2121 for f in list: |