chiark / gitweb /
Changed rebasing safety check to look for reachability of stack base (gna bug #9181).
authorYann Dirson <ydirson@altern.org>
Tue, 12 Jun 2007 21:57:06 +0000 (22:57 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 12 Jun 2007 21:57:06 +0000 (22:57 +0100)
Signed-off-by: Yann Dirson <ydirson@altern.org>
stgit/commands/common.py
stgit/commands/pull.py
stgit/commands/rebase.py
stgit/git.py
stgit/stack.py

index 22c78aec8f5a76850e70aff5c2ba8b646f0a91c0..88c60ef8760708901c339b0cffc80f701d04c355 100644 (file)
@@ -318,13 +318,22 @@ def address_or_alias(addr_str):
                  for addr in addr_str.split(',')]
     return ', '.join([addr for addr in addr_list if addr])
 
                  for addr in addr_str.split(',')]
     return ', '.join([addr for addr in addr_list if addr])
 
-def prepare_rebase(real_rebase, force=None):
+def prepare_rebase(force=None):
     if not force:
     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'
+        # Be sure we won't loose results of stg-commit by error.
+        # Note: checking for refs/bases should not be necessary with
+        # repo format version 2, but better safe than sorry.
+        branchname = crt_series.get_name()
+        # references for anything but the current stack
+        refs = [ref for ref in git.all_refs()
+                if ref != 'refs/heads/'+branchname
+                and ref != 'refs/bases/'+branchname
+                and not re.match('^refs/patches/%s/'%branchname, ref)]
+        stray_commits = git._output_lines(['git-rev-list',
+                                           crt_series.get_base(),
+                                           '--not'] + refs)
+        if len(stray_commits) != 0:
+            raise CmdException, 'Rebasing would make the following commits below the stack base unreachable: %s' % stray_commits
 
     # pop all patches
     applied = crt_series.get_applied()
 
     # pop all patches
     applied = crt_series.get_applied()
@@ -343,8 +352,6 @@ def rebase(target):
     out.done()
 
 def post_rebase(applied, nopush, merged):
     out.done()
 
 def post_rebase(applied, nopush, merged):
-    # memorize that we rebased to here
-    crt_series._set_field('orig-base', git.get_head())
     # push the patches back
     if not nopush:
         push_patches(applied, merged)
     # push the patches back
     if not nopush:
         push_patches(applied, merged)
index beaa7b5b666b1c916d51b4acbdbf9baa0b5fdaa6..bacd5fc830a6b78babec0ae6f5551a14728642c7 100644 (file)
@@ -77,16 +77,12 @@ def func(parser, options, args):
     check_conflicts()
     check_head_top_equal()
 
     check_conflicts()
     check_head_top_equal()
 
-    if policy == 'pull':
-        must_rebase = 0
-    elif policy == 'fetch-rebase':
-        must_rebase = 1
-    elif policy == 'rebase':
-        must_rebase = 1
-    else:
+    if (policy != 'pull') \
+           and (policy != 'fetch-rebase') \
+           and (policy != 'rebase'):
         raise GitConfigException, 'Unsupported pull-policy "%s"' % policy
 
         raise GitConfigException, 'Unsupported pull-policy "%s"' % policy
 
-    applied = prepare_rebase(real_rebase=must_rebase, force=options.force)
+    applied = prepare_rebase(force=options.force)
 
     # pull the remote changes
     if policy == 'pull':
 
     # pull the remote changes
     if policy == 'pull':
index 2f0e6605f7c012e5431077e740fad31c7e276493..e47772ce905fa204f33f0a78f8aadbac76cf6fc9 100644 (file)
@@ -56,7 +56,7 @@ def func(parser, options, args):
     if git_id(args[0]) == None:
         raise GitException, 'Unknown revision: %s' % git_id
         
     if git_id(args[0]) == None:
         raise GitException, 'Unknown revision: %s' % git_id
         
-    applied = prepare_rebase(real_rebase=True, force=options.force)
+    applied = prepare_rebase(force=options.force)
     rebase(args[0])
     post_rebase(applied, options.nopush, options.merged)
 
     rebase(args[0])
     post_rebase(applied, options.nopush, options.merged)
 
index 4bc41aac6b19fbfc48dad36aa83d02ee16b121fd..bec691b976390901401b122093491bb836a63ed1 100644 (file)
@@ -1070,3 +1070,9 @@ def fetch_head():
 
     # here we are sure to have a single fetch_head
     return fetch_head
 
     # here we are sure to have a single fetch_head
     return fetch_head
+
+def all_refs():
+    """Return a list of all refs in the current repository.
+    """
+
+    return [line.split()[1] for line in _output_lines(['git-show-ref'])]
index a64aff64d36f97b357b9d8b259289507ddd6f4f1..2c054073eada5312f234412332a1415aeacfffb8 100644 (file)
@@ -580,7 +580,6 @@ class Series(StgitObject):
         self.create_empty_field('applied')
         self.create_empty_field('unapplied')
         os.makedirs(self.__refs_dir)
         self.create_empty_field('applied')
         self.create_empty_field('unapplied')
         os.makedirs(self.__refs_dir)
-        self._set_field('orig-base', git.get_head())
 
         config.set(format_version_key(self.get_branch()), str(FORMAT_VERSION))
 
 
         config.set(format_version_key(self.get_branch()), str(FORMAT_VERSION))