##// END OF EJS Templates
forget: add --confirm option...
Sushil khanchi -
r37774:e7bf5a73 default
parent child Browse files
Show More
@@ -1079,9 +1079,10 b' def postcommitstatus(orig, repo, *args, '
1079 1079 finally:
1080 1080 repo.lfstatus = False
1081 1081
1082 def cmdutilforget(orig, ui, repo, match, prefix, explicitonly, dryrun):
1082 def cmdutilforget(orig, ui, repo, match, prefix, explicitonly, dryrun, confirm):
1083 1083 normalmatcher = composenormalfilematcher(match, repo[None].manifest())
1084 bad, forgot = orig(ui, repo, normalmatcher, prefix, explicitonly, dryrun)
1084 bad, forgot = orig(ui, repo, normalmatcher, prefix, explicitonly, dryrun,
1085 confirm)
1085 1086 m = composelargefilematcher(match, repo[None].manifest())
1086 1087
1087 1088 try:
@@ -63,6 +63,11 b' dryrunopts = ['
63 63 _('do not perform actions, just print output')),
64 64 ]
65 65
66 confirmopts = [
67 ('', 'confirm', None,
68 _('ask before applying actions')),
69 ]
70
66 71 remoteopts = [
67 72 ('e', 'ssh', '',
68 73 _('specify ssh command to use'), _('CMD')),
@@ -2022,7 +2027,9 b' def addwebdirpath(repo, serverpath, webc'
2022 2027 for subpath in ctx.substate:
2023 2028 ctx.sub(subpath).addwebdirpath(serverpath, webconf)
2024 2029
2025 def forget(ui, repo, match, prefix, explicitonly, dryrun):
2030 def forget(ui, repo, match, prefix, explicitonly, dryrun, confirm):
2031 if dryrun and confirm:
2032 raise error.Abort(_("cannot specify both --dry-run and --confirm"))
2026 2033 join = lambda f: os.path.join(prefix, f)
2027 2034 bad = []
2028 2035 badfn = lambda x, y: bad.append(x) or match.bad(x, y)
@@ -2038,7 +2045,8 b' def forget(ui, repo, match, prefix, expl'
2038 2045 sub = wctx.sub(subpath)
2039 2046 try:
2040 2047 submatch = matchmod.subdirmatcher(subpath, match)
2041 subbad, subforgot = sub.forget(submatch, prefix, dryrun=dryrun)
2048 subbad, subforgot = sub.forget(submatch, prefix,
2049 dryrun=dryrun, confirm=confirm)
2042 2050 bad.extend([subpath + '/' + f for f in subbad])
2043 2051 forgot.extend([subpath + '/' + f for f in subforgot])
2044 2052 except error.LookupError:
@@ -2061,8 +2069,34 b' def forget(ui, repo, match, prefix, expl'
2061 2069 % match.rel(f))
2062 2070 bad.append(f)
2063 2071
2072 if confirm:
2073 responses = _('[Ynsa?]'
2074 '$$ &Yes, forget this file'
2075 '$$ &No, skip this file'
2076 '$$ &Skip remaining files'
2077 '$$ Include &all remaining files'
2078 '$$ &? (display help)')
2079 for filename in forget[:]:
2080 r = ui.promptchoice(_('forget %s %s') % (filename, responses))
2081 if r == 4: # ?
2082 while r == 4:
2083 for c, t in ui.extractchoices(responses)[1]:
2084 ui.write('%s - %s\n' % (c, encoding.lower(t)))
2085 r = ui.promptchoice(_('forget %s %s') % (filename,
2086 responses))
2087 if r == 0: # yes
2088 continue
2089 elif r == 1: # no
2090 forget.remove(filename)
2091 elif r == 2: # Skip
2092 fnindex = forget.index(filename)
2093 del forget[fnindex:]
2094 break
2095 elif r == 3: # All
2096 break
2097
2064 2098 for f in forget:
2065 if ui.verbose or not match.exact(f):
2099 if ui.verbose or not match.exact(f) or confirm:
2066 2100 ui.status(_('removing %s\n') % match.rel(f))
2067 2101
2068 2102 if not dryrun:
@@ -112,6 +112,7 b' globalopts = ['
112 112 ]
113 113
114 114 dryrunopts = cmdutil.dryrunopts
115 confirmopts = cmdutil.confirmopts
115 116 remoteopts = cmdutil.remoteopts
116 117 walkopts = cmdutil.walkopts
117 118 commitopts = cmdutil.commitopts
@@ -2060,7 +2061,7 b' def files(ui, repo, *pats, **opts):'
2060 2061
2061 2062 @command(
2062 2063 '^forget',
2063 walkopts + dryrunopts,
2064 walkopts + dryrunopts + confirmopts,
2064 2065 _('[OPTION]... FILE...'), inferrepo=True)
2065 2066 def forget(ui, repo, *pats, **opts):
2066 2067 """forget the specified files on the next commit
@@ -2096,9 +2097,10 b' def forget(ui, repo, *pats, **opts):'
2096 2097 raise error.Abort(_('no files specified'))
2097 2098
2098 2099 m = scmutil.match(repo[None], pats, opts)
2099 dryrun = opts.get('dry_run')
2100 dryrun, confirm = opts.get('dry_run'), opts.get('confirm')
2100 2101 rejected = cmdutil.forget(ui, repo, m, prefix="",
2101 explicitonly=False, dryrun=dryrun)[0]
2102 explicitonly=False, dryrun=dryrun,
2103 confirm=confirm)[0]
2102 2104 return rejected and 1 or 0
2103 2105
2104 2106 @command(
@@ -352,7 +352,7 b' class abstractsubrepo(object):'
352 352 matched by the match function
353 353 '''
354 354
355 def forget(self, match, prefix, dryrun):
355 def forget(self, match, prefix, dryrun, confirm):
356 356 return ([], [])
357 357
358 358 def removefiles(self, matcher, prefix, after, force, subrepos,
@@ -815,10 +815,10 b' class hgsubrepo(abstractsubrepo):'
815 815 return ctx.walk(match)
816 816
817 817 @annotatesubrepoerror
818 def forget(self, match, prefix, dryrun):
818 def forget(self, match, prefix, dryrun, confirm):
819 819 return cmdutil.forget(self.ui, self._repo, match,
820 820 self.wvfs.reljoin(prefix, self._path),
821 True, dryrun=dryrun)
821 True, dryrun=dryrun, confirm=confirm)
822 822
823 823 @annotatesubrepoerror
824 824 def removefiles(self, matcher, prefix, after, force, subrepos,
@@ -272,3 +272,58 b' test --dry-run mode in forget'
272 272 [1]
273 273
274 274 $ cd ..
275
276 test --confirm option in forget
277
278 $ hg init forgetconfirm
279 $ cd forgetconfirm
280 $ echo foo > foo
281 $ hg commit -qAm "foo"
282 $ echo bar > bar
283 $ hg commit -qAm "bar"
284 $ hg forget foo --dry-run --confirm
285 abort: cannot specify both --dry-run and --confirm
286 [255]
287
288 $ hg forget foo --config ui.interactive=True --confirm << EOF
289 > ?
290 > n
291 > EOF
292 forget foo [Ynsa?] ?
293 y - yes, forget this file
294 n - no, skip this file
295 s - skip remaining files
296 a - include all remaining files
297 ? - ? (display help)
298 forget foo [Ynsa?] n
299
300 $ hg forget foo bar --config ui.interactive=True --confirm << EOF
301 > y
302 > n
303 > EOF
304 forget bar [Ynsa?] y
305 forget foo [Ynsa?] n
306 removing bar
307 $ hg status
308 R bar
309 $ hg up -qC .
310
311 $ hg forget foo bar --config ui.interactive=True --confirm << EOF
312 > s
313 > EOF
314 forget bar [Ynsa?] s
315 $ hg st
316 $ hg up -qC .
317
318 $ hg forget foo bar --config ui.interactive=True --confirm << EOF
319 > a
320 > EOF
321 forget bar [Ynsa?] a
322 removing bar
323 removing foo
324 $ hg status
325 R bar
326 R foo
327 $ hg up -qC .
328
329 $ cd ..
@@ -232,7 +232,7 b' Show all commands + options'
232 232 commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos
233 233 diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, unified, stat, root, include, exclude, subrepos
234 234 export: output, switch-parent, rev, text, git, binary, nodates, template
235 forget: include, exclude, dry-run
235 forget: include, exclude, dry-run, confirm
236 236 init: ssh, remotecmd, insecure
237 237 log: follow, follow-first, date, copies, keyword, rev, line-range, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude
238 238 merge: force, rev, preview, abort, tool
General Comments 0
You need to be logged in to leave comments. Login now