Merge branch 'js/mingw-isatty'
[gitweb.git] / builtin / pull.c
index 01b64654c5c017dd15dd98a05f750b1e723065cc..3ecb881b0bcacbf1a453bf9a6cb95ae00cdecb1d 100644 (file)
@@ -810,7 +810,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 
                if (!autostash)
                        require_clean_work_tree(N_("pull with rebase"),
-                               _("please commit or stash them."), 0);
+                               _("please commit or stash them."), 1, 0);
 
                if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
                        hashclr(rebase_fork_point);
@@ -857,10 +857,24 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                if (merge_heads.nr > 1)
                        die(_("Cannot merge multiple branches into empty head."));
                return pull_into_void(*merge_heads.sha1, curr_head);
-       } else if (opt_rebase) {
-               if (merge_heads.nr > 1)
-                       die(_("Cannot rebase onto multiple branches."));
+       }
+       if (opt_rebase && merge_heads.nr > 1)
+               die(_("Cannot rebase onto multiple branches."));
+
+       if (opt_rebase) {
+               struct commit_list *list = NULL;
+               struct commit *merge_head, *head;
+
+               head = lookup_commit_reference(orig_head);
+               commit_list_insert(head, &list);
+               merge_head = lookup_commit_reference(merge_heads.sha1[0]);
+               if (is_descendant_of(merge_head, list)) {
+                       /* we can fast-forward this without invoking rebase */
+                       opt_ff = "--ff-only";
+                       return run_merge();
+               }
                return run_rebase(curr_head, *merge_heads.sha1, rebase_fork_point);
-       } else
+       } else {
                return run_merge();
+       }
 }