##// END OF EJS Templates
remove: move most of the implementation into cmdutils.remove()...
Matt Harbison -
r23289:ae5d0a22 default
parent child Browse files
Show More
@@ -2052,6 +2052,59 b' def forget(ui, repo, match, prefix, expl'
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):
2056 ret = 0
2057 s = repo.status(match=m, clean=True)
2058 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
2059
2060 # warn about failure to delete explicit files/dirs
2061 wctx = repo[None]
2062 for f in m.files():
2063 if f in repo.dirstate or f in wctx.dirs():
2064 continue
2065 if os.path.exists(m.rel(f)):
2066 if os.path.isdir(m.rel(f)):
2067 ui.warn(_('not removing %s: no tracked files\n') % m.rel(f))
2068 else:
2069 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
2070 # missing files will generate a warning elsewhere
2071 ret = 1
2072
2073 if force:
2074 list = modified + deleted + clean + added
2075 elif after:
2076 list = deleted
2077 for f in modified + added + clean:
2078 ui.warn(_('not removing %s: file still exists\n') % m.rel(f))
2079 ret = 1
2080 else:
2081 list = deleted + clean
2082 for f in modified:
2083 ui.warn(_('not removing %s: file is modified (use -f'
2084 ' to force removal)\n') % m.rel(f))
2085 ret = 1
2086 for f in added:
2087 ui.warn(_('not removing %s: file has been marked for add'
2088 ' (use forget to undo)\n') % m.rel(f))
2089 ret = 1
2090
2091 for f in sorted(list):
2092 if ui.verbose or not m.exact(f):
2093 ui.status(_('removing %s\n') % m.rel(f))
2094
2095 wlock = repo.wlock()
2096 try:
2097 if not after:
2098 for f in list:
2099 if f in added:
2100 continue # we never unlink added files on remove
2101 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
2102 repo[None].forget(list)
2103 finally:
2104 wlock.release()
2105
2106 return ret
2107
2055 def cat(ui, repo, ctx, matcher, prefix, **opts):
2108 def cat(ui, repo, ctx, matcher, prefix, **opts):
2056 err = 1
2109 err = 1
2057
2110
@@ -5125,62 +5125,12 b' def remove(ui, repo, *pats, **opts):'
5125 Returns 0 on success, 1 if any warnings encountered.
5125 Returns 0 on success, 1 if any warnings encountered.
5126 """
5126 """
5127
5127
5128 ret = 0
5129 after, force = opts.get('after'), opts.get('force')
5128 after, force = opts.get('after'), opts.get('force')
5130 if not pats and not after:
5129 if not pats and not after:
5131 raise util.Abort(_('no files specified'))
5130 raise util.Abort(_('no files specified'))
5132
5131
5133 m = scmutil.match(repo[None], pats, opts)
5132 m = scmutil.match(repo[None], pats, opts)
5134 s = repo.status(match=m, clean=True)
5133 return cmdutil.remove(ui, repo, m, after, force)
5135 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
5136
5137 # warn about failure to delete explicit files/dirs
5138 wctx = repo[None]
5139 for f in m.files():
5140 if f in repo.dirstate or f in wctx.dirs():
5141 continue
5142 if os.path.exists(m.rel(f)):
5143 if os.path.isdir(m.rel(f)):
5144 ui.warn(_('not removing %s: no tracked files\n') % m.rel(f))
5145 else:
5146 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
5147 # missing files will generate a warning elsewhere
5148 ret = 1
5149
5150 if force:
5151 list = modified + deleted + clean + added
5152 elif after:
5153 list = deleted
5154 for f in modified + added + clean:
5155 ui.warn(_('not removing %s: file still exists\n') % m.rel(f))
5156 ret = 1
5157 else:
5158 list = deleted + clean
5159 for f in modified:
5160 ui.warn(_('not removing %s: file is modified (use -f'
5161 ' to force removal)\n') % m.rel(f))
5162 ret = 1
5163 for f in added:
5164 ui.warn(_('not removing %s: file has been marked for add'
5165 ' (use forget to undo)\n') % m.rel(f))
5166 ret = 1
5167
5168 for f in sorted(list):
5169 if ui.verbose or not m.exact(f):
5170 ui.status(_('removing %s\n') % m.rel(f))
5171
5172 wlock = repo.wlock()
5173 try:
5174 if not after:
5175 for f in list:
5176 if f in added:
5177 continue # we never unlink added files on remove
5178 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
5179 repo[None].forget(list)
5180 finally:
5181 wlock.release()
5182
5183 return ret
5184
5134
5185 @command('rename|move|mv',
5135 @command('rename|move|mv',
5186 [('A', 'after', None, _('record a rename that has already occurred')),
5136 [('A', 'after', None, _('record a rename that has already occurred')),
General Comments 0
You need to be logged in to leave comments. Login now