Add '--update' option to 'refresh'
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 13 Jul 2007 22:43:55 +0000 (23:43 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 13 Jul 2007 22:43:55 +0000 (23:43 +0100)
This option is similar to the one from 'pick'. It only updates the
files already part of the current patch.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/refresh.py

index 77dcbda..911c127 100644 (file)
@@ -47,6 +47,9 @@ options = [make_option('-f', '--force',
            make_option('-s', '--showpatch',
                        help = 'show the patch content in the editor buffer',
                        action = 'store_true'),
+           make_option('--update',
+                       help = 'only update the current patch files',
+                       action = 'store_true'),
            make_option('--undo',
                        help = 'revert the commit generated by the last refresh',
                        action = 'store_true'),
@@ -83,7 +86,7 @@ def func(parser, options, args):
         check_conflicts()
 
     if options.patch:
-        if args:
+        if args or options.update:
             raise CmdException, \
                   'Only full refresh is available with the --patch option'
         patch = options.patch
@@ -115,8 +118,11 @@ def func(parser, options, args):
     else:
         sign_str = None
 
-    if git.local_changes() \
-           or not crt_series.head_top_equal() \
+    files = [x[1] for x in git.tree_status(verbose = True)]
+    if args:
+        files = [f for f in files if f in args]
+
+    if files or not crt_series.head_top_equal() \
            or options.edit or options.message \
            or options.authname or options.authemail or options.authdate \
            or options.commname or options.commemail \
@@ -126,12 +132,20 @@ def func(parser, options, args):
             applied = crt_series.get_applied()
             between = applied[:applied.index(patch):-1]
             pop_patches(between, keep = True)
+        elif options.update:
+            rev1 = git_id('//bottom')
+            rev2 = git_id('//top')
+            patch_files = git.barefiles(rev1, rev2).split('\n')
+            files = [f for f in files if f in patch_files]
+            if not files:
+                out.info('No modified files for updating patch "%s"' % patch)
+                return
 
         out.start('Refreshing patch "%s"' % patch)
 
         if autoresolved == 'yes':
             resolved_all()
-        crt_series.refresh_patch(files = args,
+        crt_series.refresh_patch(files = files,
                                  message = options.message,
                                  edit = options.edit,
                                  show_patch = options.showpatch,