comparison mercurial/cmdutil.py @ 37756:e7bf5a73e4e1

forget: add --confirm option Also added confirmopts in cmdutil.py Differential Revision: https://phab.mercurial-scm.org/D2934
author Sushil khanchi <sushilkhanchi97@gmail.com>
date Thu, 22 Mar 2018 16:11:42 +0530
parents 5537d8f5e989
children 7269b87f817c
comparison
equal deleted inserted replaced
37755:886754323bed 37756:e7bf5a73e4e1
59 # templates of common command options 59 # templates of common command options
60 60
61 dryrunopts = [ 61 dryrunopts = [
62 ('n', 'dry-run', None, 62 ('n', 'dry-run', None,
63 _('do not perform actions, just print output')), 63 _('do not perform actions, just print output')),
64 ]
65
66 confirmopts = [
67 ('', 'confirm', None,
68 _('ask before applying actions')),
64 ] 69 ]
65 70
66 remoteopts = [ 71 remoteopts = [
67 ('e', 'ssh', '', 72 ('e', 'ssh', '',
68 _('specify ssh command to use'), _('CMD')), 73 _('specify ssh command to use'), _('CMD')),
2020 for r in repo.revs('filelog("path:.hgsub")'): 2025 for r in repo.revs('filelog("path:.hgsub")'):
2021 ctx = repo[r] 2026 ctx = repo[r]
2022 for subpath in ctx.substate: 2027 for subpath in ctx.substate:
2023 ctx.sub(subpath).addwebdirpath(serverpath, webconf) 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 join = lambda f: os.path.join(prefix, f) 2033 join = lambda f: os.path.join(prefix, f)
2027 bad = [] 2034 bad = []
2028 badfn = lambda x, y: bad.append(x) or match.bad(x, y) 2035 badfn = lambda x, y: bad.append(x) or match.bad(x, y)
2029 wctx = repo[None] 2036 wctx = repo[None]
2030 forgot = [] 2037 forgot = []
2036 2043
2037 for subpath in sorted(wctx.substate): 2044 for subpath in sorted(wctx.substate):
2038 sub = wctx.sub(subpath) 2045 sub = wctx.sub(subpath)
2039 try: 2046 try:
2040 submatch = matchmod.subdirmatcher(subpath, match) 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 bad.extend([subpath + '/' + f for f in subbad]) 2050 bad.extend([subpath + '/' + f for f in subbad])
2043 forgot.extend([subpath + '/' + f for f in subforgot]) 2051 forgot.extend([subpath + '/' + f for f in subforgot])
2044 except error.LookupError: 2052 except error.LookupError:
2045 ui.status(_("skipping missing subrepository: %s\n") 2053 ui.status(_("skipping missing subrepository: %s\n")
2046 % join(subpath)) 2054 % join(subpath))
2059 ui.warn(_('not removing %s: ' 2067 ui.warn(_('not removing %s: '
2060 'file is already untracked\n') 2068 'file is already untracked\n')
2061 % match.rel(f)) 2069 % match.rel(f))
2062 bad.append(f) 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 for f in forget: 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 ui.status(_('removing %s\n') % match.rel(f)) 2100 ui.status(_('removing %s\n') % match.rel(f))
2067 2101
2068 if not dryrun: 2102 if not dryrun:
2069 rejected = wctx.forget(forget, prefix) 2103 rejected = wctx.forget(forget, prefix)
2070 bad.extend(f for f in rejected if f in match.files()) 2104 bad.extend(f for f in rejected if f in match.files())