Thread (1 message) 1 message, 1 author, 2016-06-15
DORMANTno replies

[PATCH 01/03] Add helper function for branch tag and commitish to git.el

From: Rémi Vanicat <hidden>
Date: 2016-06-15 22:44:14
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

---
 contrib/emacs/git.el |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index a8bf0ef..16d9771 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1138,6 +1138,43 @@ 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-branches (&optional all)
+  "Return an alist of available branches
+if all is non-nil, return all branch, otherwise only local one
+cdr of assoc is non-nil for the current branch
+nil otherwise"
+  (let ((branches ()))
+    (with-temp-buffer
+      (if all
+	  (git-run-command-buffer (current-buffer) "branch" "-a")
+	  (git-run-command-buffer (current-buffer) "branch"))
+      (goto-char (point-min))
+      (while (re-search-forward "^\\([ *]\\) \\([^\n]*\\)$" () t)
+	(push (cons (match-string 2)
+		    (string= (match-string 1) "*"))
+	      branches)))
+    (nreverse branches)))
+
+(defun git-list-tags ()
+  "Return an list of available tags"
+  (let ((tags ()))
+    (with-temp-buffer
+      (git-run-command-buffer (current-buffer) "tag")
+      (goto-char (point-min))
+      (while (re-search-forward "^\\([^\n]+\\)$" () t)
+	(push (match-string 1)
+	      tags)))
+    (nreverse tags)))
+
+(defun git-read-commitish (prompt &optional default)
+  "ask user, with commpletion for a commit, branch, tag or any commitish"
+  (completing-read prompt (list* "HEAD"
+				 "ORIG_HEAD"
+				 "FETCH_HEAD"
+				 (append (git-list-branches t)
+					 (git-list-tags)))
+		   () () () () default))
+
 (defun git-diff-file ()
   "Diff the marked file(s) against HEAD."
   (interactive)
-- 
1.5.4.1.123.gcb68-dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help