From 22ee4f768511ec74750a2cbb27b7a6d743ed0c26 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Wed, 13 Aug 2008 05:28:16 +0300 Subject: [PATCH] Rebasing. --- magit.el | 37 ++++++++++++++++++++++++++++++++++++- magit.texi | 19 +++++++++++++------ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/magit.el b/magit.el index fb5d41ab..aeae654e 100644 --- a/magit.el +++ b/magit.el @@ -17,7 +17,7 @@ ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. -;;; Introduction +;;; Commentary ;; Invoking the magit-status function will show a buffer with the ;; current status of the current git repository and its checkout. @@ -223,6 +223,7 @@ (define-key map (kbd "B") 'magit-create-branch) (define-key map (kbd "m") 'magit-manual-merge) (define-key map (kbd "M") 'magit-automatic-merge) + (define-key map (kbd "R") 'magit-rebase-step) (define-key map (kbd "U") 'magit-pull) (define-key map (kbd "P") 'magit-push) (define-key map (kbd "c") 'magit-log-edit) @@ -423,6 +424,9 @@ pushed. (magit-concat-with-delim ", " (mapcar 'magit-name-rev merge-heads)))))) + (let ((rebase (magit-rebase-info))) + (if rebase + (insert (apply 'format "Rebasing: %s (%s of %s)\n" rebase)))) (insert "\n") (magit-insert-section 'untracked "Untracked files:" 'magit-wash-other-files @@ -590,6 +594,37 @@ pushed. (interactive (list (magit-read-rev "Merge from branch: "))) (magit-run "git" "merge" branch)) +;;; Rebasing + +(defun magit-rebase-info () + (cond ((file-exists-p ".dotest") + (list (magit-name-rev (car (magit-file-lines ".dotest/onto"))) + (car (magit-file-lines ".dotest/next")) + (car (magit-file-lines ".dotest/last")))) + ((file-exists-p ".git/.dotest-merge") + (list (car (magit-file-lines ".git/.dotest-merge/onto_name")) + (car (magit-file-lines ".git/.dotest-merge/msgnum")) + (car (magit-file-lines ".git/.dotest-merge/end")))) + (t + nil))) + +(defun magit-rebase-step () + (interactive) + (let ((info (magit-rebase-info))) + (if (not info) + (magit-run "git" "rebase" (magit-read-rev "Rebase against: ")) + (let ((cursor-in-echo-area t) + (message-log-max nil)) + (message "Rebase in progress. Abort, Skip, or Continue? ") + (let ((reply (read-event))) + (case reply + ((?A ?a) + (magit-run "git" "rebase" "--abort")) + ((?S ?s) + (magit-run "git" "rebase" "--skip")) + ((?C ?c) + (magit-run "git" "rebase" "--continue")))))))) + ;;; Resetting (defun magit-reset-soft (target) diff --git a/magit.texi b/magit.texi index e398656b..8d49bdf1 100644 --- a/magit.texi +++ b/magit.texi @@ -194,8 +194,8 @@ You can also mark the current commit by typing @kbd{.}. Once you have marked a commit, you can show the differences between it and the current commit by typing @kbd{=}. -@node Rewriting History -@chapter Rewriting History +@node Resetting +@chapter Resetting Once you have added a commit to your local repository, you can not change it anymore in any way. But you can reset your current head to @@ -224,9 +224,6 @@ current head, but it will reset your working tree and staging area back to the last comitted state. You can do this to abort a manual merge, for example. -Rebasing is a more powerful way to rewrite history. It is so -powerful, it has its own chapter. See @ref{Rebasing}. - @node Branching and Merging @chapter Branching and Merging @@ -269,7 +266,17 @@ from a merge, you should abort it. @node Rebasing @chapter Rebasing -not yet implemented. +Typing @kbd{R} in the status buffer will initiate a rebase or, if one +is already in progress, ask you how to continue. + +When a rebase is stopped in the middle because of a conflict, the +header of the status buffer will indicate what you are rebasing your +current branch onto and how far along you are in the series of commits +that are being replayed. + +Of course, you can initiate a rebase in any number of ways, by +configuring @code{git pull} to rebase instead of merge, for example. +Such a rebase can be finished with Magit as well. @node Pushing and Pulling @chapter Pushing and Pulling