[PATCH 5/5] Refuse to pull/rebase when rendered unsafe by (un)commits.
This can be overriden by a new --force flag.
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
stgit/commands/common.py | 9 ++++++++-
stgit/commands/pull.py | 8 ++++++--
stgit/commands/rebase.py | 5 ++++-
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 56cb517..398231a 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -347,7 +347,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:
diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py
index 83a2725..990244e 100644
--- a/stgit/commands/pull.py
+++ b/stgit/commands/pull.py
@@ -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)
diff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py
index 63f18ec..d132b60 100644
--- a/stgit/commands/rebase.py
+++ b/stgit/commands/rebase.py
@@ -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)