X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/170f576bb9eac1dafc139de7b51226d78d31cbbe..f7ed76a9b6158888e8efe2faef9c095802fd93fe:/stgit/commands/resolved.py diff --git a/stgit/commands/resolved.py b/stgit/commands/resolved.py index 2c968d0..1130641 100644 --- a/stgit/commands/resolved.py +++ b/stgit/commands/resolved.py @@ -22,6 +22,8 @@ from optparse import OptionParser, make_option from stgit.commands.common import * from stgit.utils import * from stgit import stack, git, basedir +from stgit.config import config, file_extensions +from stgit.gitmergeonefile import interactive_merge help = 'mark a file conflict as solved' @@ -29,44 +31,60 @@ usage = """%prog [options] [] Mark a merge conflict as resolved. The conflicts can be seen with the 'status' command, the corresponding files being prefixed with a -'C'. This command also removes any .{local,remote,older} files.""" +'C'. This command also removes any .{ancestor,current,patched} +files.""" options = [make_option('-a', '--all', help = 'mark all conflicts as solved', action = 'store_true'), - make_option('-r', '--reset', metavar = '(local|remote|older)', - help = 'reset the file(s) to the given state')] - + make_option('-r', '--reset', metavar = '(ancestor|current|patched)', + help = 'reset the file(s) to the given state'), + make_option('-i', '--interactive', + help = 'run the interactive merging tool', + action = 'store_true')] def func(parser, options, args): """Mark the conflict as resolved """ - if options.reset and options.reset not in ['local', 'remote', 'older']: + if options.reset \ + and options.reset not in file_extensions(): raise CmdException, 'Unknown reset state: %s' % options.reset - if options.all: + if options.all and not options.interactive: resolved_all(options.reset) return - if len(args) == 0: + conflicts = git.get_conflicts() + + if len(args) != 0: + files = args + elif options.all: + files = conflicts + else: parser.error('incorrect number of arguments') - conflicts = git.get_conflicts() if not conflicts: raise CmdException, 'No more conflicts' + # check for arguments validity - for filename in args: - if not filename in conflicts: - raise CmdException, 'No conflicts for "%s"' % filename - # resolved - for filename in args: - resolved(filename, options.reset) - del conflicts[conflicts.index(filename)] + if not options.all: + for filename in files: + if not filename in conflicts: + raise CmdException, 'No conflicts for "%s"' % filename - # save or remove the conflicts file - if conflicts == []: - os.remove(os.path.join(basedir.get(), 'conflicts')) - else: - f = file(os.path.join(basedir.get(), 'conflicts'), 'w+') - f.writelines([line + '\n' for line in conflicts]) - f.close() + # resolved + try: + for filename in files: + if options.interactive: + interactive_merge(filename) + resolved(filename, options.reset) + del conflicts[conflicts.index(filename)] + finally: + # save or remove the conflicts file. Needs a finally clause to + # ensure that already solved conflicts are marked + if conflicts == []: + os.remove(os.path.join(basedir.get(), 'conflicts')) + else: + f = file(os.path.join(basedir.get(), 'conflicts'), 'w+') + f.writelines([line + '\n' for line in conflicts]) + f.close()