[PATCH 02/03] Adding checkout function for commitish in git.el

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



M-x git-checkout ask for a commitish, and checkout it as in
  git checkout commitish --
  key binding: "C"
M-x git-branch ask for the name of a new branch, create it and
checkout it as in
  git checkout -b name
  key binding: "b"
M-x git-create-branch ask for a new branchname, a startpoint (a
commitish) and create a new branch as in
  git branch branchname startpoint
  key binding "B"
A menu is also available for just switching branch
---
The main problem that I still see, is the error message when one try
to checkout a branch/tag... that doesn't exist: it is a cryptic error
message... 

 contrib/emacs/git.el |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 16d9771..f180421 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1175,6 +1175,44 @@ nil otherwise"
 					 (git-list-tags)))
 		   () () () () default))
 
+(defun git-checkout (branch &optional merge)
+  "checkout a branch, tag, or any commitish
+
+use a prefix arg if git should merge while checking out"
+  (interactive
+   (list (git-read-commitish "Branch: ")
+	 current-prefix-arg))
+  (let ((args (list branch "--")))
+    (if merge (push "-m" args))
+    (if (apply #'git-call-process-display-error "checkout" args)
+	(git-refresh-status))))
+
+(defun git-branch (branch)
+  "branch from current commit and checkout the new branch"
+  (interactive "MBranch: ")
+  (if (git-call-process-display-error "checkout" "-b" branch)
+      (git-refresh-status)))
+
+(defun git-create-branch (branch start-point)
+  "create a new branch named [branch] from the [start-point]"
+  (interactive
+   (list (read-string "New branch: ")
+	 (git-read-commitish "Start point(HEAD): " "HEAD")))
+  (git-call-process-display-error "branch" branch start-point))
+
+(defun git-checkout-menu-filter (rest)
+  "define the change branch menu"
+  (append
+   (mapcar
+    (lambda (branch)
+      `[,(car branch)
+	 (git-checkout ,(car branch))
+	 :style radio
+	 :selected ,(cdr branch)])
+    (git-list-branches))
+   (list ["checkout any commitish" git-checkout t]
+	 ["change to new" git-branch t])))
+
 (defun git-diff-file ()
   "Diff the marked file(s) against HEAD."
   (interactive)
@@ -1466,6 +1504,9 @@ amended version of it."
     (define-key map "a"   'git-add-file)
     (define-key map "c"   'git-commit-file)
     (define-key map "\C-c" commit-map)
+    (define-key map "C"   'git-checkout)
+    (define-key map "b"   'git-branch)
+    (define-key map "B"   'git-create-branch)
     (define-key map "d"    diff-map)
     (define-key map "="   'git-diff-file)
     (define-key map "f"   'git-find-file)
@@ -1513,6 +1554,7 @@ amended version of it."
     `("Git"
       ["Refresh" git-refresh-status t]
       ["Commit" git-commit-file t]
+      ("Checkout Branch" :filter git-checkout-menu-filter)
       ("Merge"
 	["Next Unmerged File" git-next-unmerged-file t]
 	["Prev Unmerged File" git-prev-unmerged-file t]
-- 
1.5.4.1.123.gcb68-dirty


-- 
Rémi Vanicat
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux