Infrastructure for current directory handling
[stgit] / stgit / commands / pull.py
index ad485a5..5fcf2cc 100644 (file)
@@ -38,14 +38,12 @@ resolved and the patch pushed again.
 
 Check the 'git fetch' documentation for the <repository> format."""
 
+directory = DirectoryHasRepository()
 options = [make_option('-n', '--nopush',
                        help = 'do not push the patches back after pulling',
                        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):
@@ -78,16 +76,10 @@ def func(parser, options, args):
     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 not in ['pull', 'fetch-rebase', 'rebase']:
         raise GitConfigException, 'Unsupported pull-policy "%s"' % policy
 
-    applied = prepare_rebase(force=options.force)
+    applied = prepare_rebase()
 
     # pull the remote changes
     if policy == 'pull':
@@ -96,7 +88,14 @@ def func(parser, options, args):
     elif policy == 'fetch-rebase':
         out.info('Fetching from "%s"' % repository)
         git.fetch(repository)
-        rebase(git.fetch_head())
+        try:
+            target = git.fetch_head()
+        except git.GitException:
+            out.error('Could not find the remote head to rebase onto, pushing any patches back...')
+            post_rebase(applied, False, False)
+            raise CmdException, 'Could not find the remote head to rebase onto - fix branch.%s.merge in .git/config' % crt_series.get_name()
+
+        rebase(target)
     elif policy == 'rebase':
         rebase(crt_series.get_parent_branch())