[StGit PATCH 11/15] Clean up the logic in "stg resolved"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For example, complain if the user gives both --all and one or more
filenames.

Signed-off-by: Karl Hasselström <kha@xxxxxxxxxxx>

---

 stgit/commands/resolved.py |   50 ++++++++++++++++++--------------------------
 1 files changed, 20 insertions(+), 30 deletions(-)


diff --git a/stgit/commands/resolved.py b/stgit/commands/resolved.py
index 0b3ab81..baf34a3 100644
--- a/stgit/commands/resolved.py
+++ b/stgit/commands/resolved.py
@@ -33,45 +33,35 @@ Mark a merge conflict as resolved. The conflicts can be seen with the
 'status' command, the corresponding files being prefixed with a
 'C'."""
 
-options = [make_option('-a', '--all',
-                       help = 'mark all conflicts as solved',
-                       action = 'store_true'),
+options = [make_option('-a', '--all', action = 'store_true',
+                       help = 'resolve all conflicting files'),
            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')]
+           make_option('-i', '--interactive', action = 'store_true',
+                       help = 'run the interactive merging tool')]
 
 def func(parser, options, args):
-    """Mark the conflict as resolved
-    """
-    if options.reset \
-           and options.reset not in file_extensions():
+    """Mark the conflict as resolved."""
+
+    # Make sure the user didn't feed us bogus arguments.
+    if options.all and args:
+        parser.error('cannot specify both --all and individual files')
+    if not (options.all or args):
+        parser.error('must specify either --all or one or more files')
+    if options.reset and options.reset not in file_extensions():
         raise CmdException, 'Unknown reset state: %s' % options.reset
 
-    if options.all and not options.interactive:
-        resolved_all(options.reset)
-        return
-
-    conflicts = git.get_conflicts()
-
-    if len(args) != 0:
-        files = args
-    elif options.all:
+    # Compute the set of files to resolve.
+    conflicts = set(git.get_conflicts())
+    if options.all:
         files = conflicts
     else:
-        parser.error('incorrect number of arguments')
-
-    if not conflicts:
-        raise CmdException, 'No more conflicts'
-
-    # check for arguments validity
-    if not options.all:
-        for filename in files:
-            if not filename in conflicts:
-                raise CmdException, 'No conflicts for "%s"' % filename
+        files = set(args) & conflicts  # ignore any non-conflicting files
+    if not files:
+        out.info('No conflicts to resolve')
+        return
 
-    # resolved
+    # Do the actual resolving.
     if options.interactive:
         for filename in files:
             interactive_merge(filename)

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux