comparison mercurial/cmdutil.py @ 27985:79139c7a88bd

revert: makes interactive mode ask to forget added files (issue4936) Before this patch revert interactive mode unconditionally forgets added files. This patch fixes this by asking user if he wants to forget added file. If user doesn't want to forget given file, it is added to matcher_opts exclude list, to not reviewing it later with other modified files.
author liscju <piotr.listkiewicz@gmail.com>
date Fri, 05 Feb 2016 15:18:40 +0100
parents ce9696193175
children d3f1b7ee5e70
comparison
equal deleted inserted replaced
27984:e60e13a86529 27985:79139c7a88bd
3128 3128
3129 Make sure you have the working directory locked when calling this function. 3129 Make sure you have the working directory locked when calling this function.
3130 """ 3130 """
3131 parent, p2 = parents 3131 parent, p2 = parents
3132 node = ctx.node() 3132 node = ctx.node()
3133 excluded_files = []
3134 matcher_opts = {"exclude": excluded_files}
3135
3133 def checkout(f): 3136 def checkout(f):
3134 fc = ctx[f] 3137 fc = ctx[f]
3135 repo.wwrite(f, fc.data(), fc.flags()) 3138 repo.wwrite(f, fc.data(), fc.flags())
3136 3139
3137 audit_path = pathutil.pathauditor(repo.root) 3140 audit_path = pathutil.pathauditor(repo.root)
3138 for f in actions['forget'][0]: 3141 for f in actions['forget'][0]:
3139 repo.dirstate.drop(f) 3142 if interactive:
3143 choice = \
3144 repo.ui.promptchoice(
3145 _("forget added file %s (yn)?$$ &Yes $$ &No")
3146 % f)
3147 if choice == 0:
3148 repo.dirstate.drop(f)
3149 else:
3150 excluded_files.append(repo.wjoin(f))
3151 else:
3152 repo.dirstate.drop(f)
3140 for f in actions['remove'][0]: 3153 for f in actions['remove'][0]:
3141 audit_path(f) 3154 audit_path(f)
3142 try: 3155 try:
3143 util.unlinkpath(repo.wjoin(f)) 3156 util.unlinkpath(repo.wjoin(f))
3144 except OSError: 3157 except OSError:
3160 3173
3161 newlyaddedandmodifiedfiles = set() 3174 newlyaddedandmodifiedfiles = set()
3162 if interactive: 3175 if interactive:
3163 # Prompt the user for changes to revert 3176 # Prompt the user for changes to revert
3164 torevert = [repo.wjoin(f) for f in actions['revert'][0]] 3177 torevert = [repo.wjoin(f) for f in actions['revert'][0]]
3165 m = scmutil.match(ctx, torevert, {}) 3178 m = scmutil.match(ctx, torevert, matcher_opts)
3166 diffopts = patch.difffeatureopts(repo.ui, whitespace=True) 3179 diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
3167 diffopts.nodates = True 3180 diffopts.nodates = True
3168 diffopts.git = True 3181 diffopts.git = True
3169 reversehunks = repo.ui.configbool('experimental', 3182 reversehunks = repo.ui.configbool('experimental',
3170 'revertalternateinteractivemode', 3183 'revertalternateinteractivemode',