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

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

From: Alexandre Julliard <hidden>
Date: 2016-06-15 22:44:14

Rémi Vanicat [off-list ref] writes:
+(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)))
git-run-command-buffer isn't really what you want to use here, look at
how other functions that use a temp-buffer do it. Also that alist thing
is ugly, there are better ways of finding the current branch if we need
it. Besides, you probably want to use git-for-each-ref instead of
git-branch, git-branch is a bit too porcelainish IMO.

-- 
Alexandre Julliard
julliard@winehq.org
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help