chiark / gitweb /
Refuse to pull/rebase when rendered unsafe by (un)commits.
authorYann Dirson <ydirson@altern.org>
Tue, 20 Feb 2007 00:14:24 +0000 (01:14 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 21 Feb 2007 18:42:24 +0000 (18:42 +0000)
This can be overriden by a new --force flag.

Signed-off-by: Yann Dirson <ydirson@altern.org>
stgit/commands/common.py
stgit/commands/pull.py
stgit/commands/rebase.py

index 2ef845421c8edc6cd7478b56f1a004c2c2752147..ed71f744f6a22b54cf382deb313fc72fb01ac94f 100644 (file)
@@ -348,7 +348,14 @@ def make_patch_name(msg, unacceptable, default_name = 'patch',
         patchname = '%s-%d' % (patchname, suffix)
     return patchname
 
-def prepare_rebase():
+def prepare_rebase(real_rebase, force=None):
+    if not force:
+        # Be sure we won't loose results of stg-(un)commit by error.
+        # Do not require an existing orig-base for compatibility with 0.12 and earlier.
+        origbase = crt_series._get_field('orig-base')
+        if origbase and crt_series.get_base() != origbase:
+            raise CmdException, 'Rebasing would possibly lose data'
+
     # pop all patches
     applied = crt_series.get_applied()
     if len(applied) > 0:
index 83a2725cbdbcd2279150d365c9157b9e37d50df1..990244ebf77d178bcd1bb6dc30fb40799e65de7a 100644 (file)
@@ -41,6 +41,9 @@ options = [make_option('-n', '--nopush',
                        action = 'store_true'),
            make_option('-m', '--merged',
                        help = 'check for patches merged upstream',
+                       action = 'store_true'),
+           make_option('--force',
+                       help = 'force rebase even if the stack based was moved by (un)commits',
                        action = 'store_true')]
 
 def func(parser, options, args):
@@ -61,12 +64,13 @@ def func(parser, options, args):
     check_conflicts()
     check_head_top_equal()
 
-    applied = prepare_rebase()
+    must_rebase = (config.get('stgit.pull-does-rebase') == 'yes')
+    applied = prepare_rebase(real_rebase=must_rebase, force=options.force)
 
     # pull the remote changes
     print 'Pulling from "%s"...' % repository
     git.fetch(repository)
-    if (config.get('stgit.pull-does-rebase') == 'yes'):
+    if must_rebase:
         rebase(git.fetch_head())
 
     post_rebase(applied, options.nopush, options.merged)
index 63f18ec6e7ebd66e499739510b86e4047f75c8bd..d132b60bce951d60b724e1fd767822074524fd4c 100644 (file)
@@ -34,6 +34,9 @@ options = [make_option('-n', '--nopush',
                        action = 'store_true'),
            make_option('-m', '--merged',
                        help = 'check for patches merged upstream',
+                       action = 'store_true'),
+           make_option('--force',
+                       help = 'force rebase even if the stack based was moved by (un)commits',
                        action = 'store_true')]
 
 def func(parser, options, args):
@@ -49,7 +52,7 @@ def func(parser, options, args):
     check_conflicts()
     check_head_top_equal()
 
-    applied = prepare_rebase()
+    applied = prepare_rebase(real_rebase=True, force=options.force)
     rebase(args[0])
     post_rebase(applied, options.nopush, options.merged)