git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add function to checkout a branch in git.el
@ 2008-02-13 15:53 =?utf-8?q?R=C3=A9mi=20Vanicat?=
  2008-02-13 16:30 ` Karl Hasselström
  2008-02-13 18:29 ` [PATCH] Add function to checkout a branch " Sergei Organov
  0 siblings, 2 replies; 14+ messages in thread
From: =?utf-8?q?R=C3=A9mi=20Vanicat?= @ 2008-02-13 15:53 UTC (permalink / raw)
  To: git; +Cc: Alexandre Julliard

One can now:
- checkout an existing branch with M-x git-change-branch
- create and checkout a new branch with C-u M-x git-change-branch
- do all this from the Git menu
---
It could also be interesting to add some  key biding for those

Also one might want to update the *git-status* buffer after checkout,
but this is not done by this patch
 contrib/emacs/git.el |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index a8bf0ef..404c8e6 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1138,6 +1138,50 @@ Return the list of files that haven't been handled."
   (when (eq (window-buffer) (current-buffer))
     (shrink-window-if-larger-than-buffer)))
 
+(defun git-list-branch ()
+  "Return a list of available branch"
+  ;; should I check if I'm in a git repository ?
+  (let ((branchs ()))
+    (with-temp-buffer
+      (git-run-command-buffer (current-buffer) "branch")
+      (goto-char (point-min))
+      (while (re-search-forward "^\\([ *]\\) \\([^\n]*\\)$" () t)
+	(push (list (match-string 2)
+		    (string= (match-string 1) "*"))
+	      branchs)))
+    (nreverse branchs)))
+
+(defun git-change-branch (branch &optional new)
+  "Switch to another branch
+
+With a prefix argument, switch to a new branch, ortherwise use
+an existing one"
+  (interactive
+   (if current-prefix-arg
+       (list (read-from-minibuffer "Branch: ")
+	     current-prefix-arg)
+       (list (completing-read "Branch: " (git-list-branch) () t)
+	     current-prefix-arg)))
+  (with-temp-buffer
+    (if new
+	(git-call-process-display-error "checkout" "-b" branch)
+	(git-call-process-display-error "checkout" branch))
+    (goto-char (point-min))))
+
+(defun git-change-new-branch-menu (branch)
+  "Switch to new branch"
+  (interactive "MBranch: ")
+  (git-change-branch branch 't))
+
+(defun git-change-branch-menu-filter (rest)
+  "define the change branch menu"
+  (append
+   (mapcar
+    (lambda (branch)
+      `[,(car branch) (git-change-branch ,(car branch)) t])
+    (git-list-branch))
+   (list ["change to new" git-change-new-branch-menu t])))
+
 (defun git-diff-file ()
   "Diff the marked file(s) against HEAD."
   (interactive)
@@ -1486,6 +1530,7 @@ amended version of it."
 	["Diff Against Merge Head" git-diff-file-merge-head t]
 	["Diff Against Mine" git-diff-file-mine t]
 	["Diff Against Other" git-diff-file-other t])
+      ("Change branch" :filter git-change-branch-menu-filter)
       "--------"
       ["Add File" git-add-file t]
       ["Revert File" git-revert-file t]
-- 
1.5.4.1.101.gacba

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2008-02-17 18:31 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-13 15:53 [PATCH] Add function to checkout a branch in git.el =?utf-8?q?R=C3=A9mi=20Vanicat?=
2008-02-13 16:30 ` Karl Hasselström
2008-02-13 16:43   ` Karl Hasselström
2008-02-13 18:09     ` Remi Vanicat
2008-02-13 18:23     ` Sergei Organov
2008-02-13 21:04       ` Karl Hasselström
2008-02-14 11:47         ` Sergei Organov
2008-02-16 19:17       ` [patch v2] switching and creating branch, merging and rebasing with Emacs =?utf-8?q?R=C3=A9mi=20Vanicat?=
2008-02-16 19:27         ` [PATCH 01/03] Add helper function for branch tag and commitish to git.el Rémi Vanicat
2008-02-17 18:30           ` Alexandre Julliard
2008-02-16 19:30         ` [PATCH 02/03] Adding checkout function for commitish in git.el Rémi Vanicat
2008-02-17 18:27           ` Alexandre Julliard
2008-02-16 19:35         ` [PATCH 03/03] Adding command for merging " Rémi Vanicat
2008-02-13 18:29 ` [PATCH] Add function to checkout a branch " Sergei Organov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).