Sorting branch names by most recently used

40 views
Skip to first unread message

Martin Geisler

unread,
Nov 23, 2016, 7:59:15 AM11/23/16
to Magit Maling list
Hi all,

Does Magit have an option to sort branch names by the order they have been used?

I'm using magit-ido-completing-read and as far as I can tell, the
order of the branches is alphabetically. That is normally not such a
big problem since typing a few characters narrows the list down.
However, I recently started having both a "release-2.0" and a
"release-2.1" branch in my repository -- and now find myself
repeatedly typing "rel21" to pick the right one :-)

Any hints on how to have the completion function order the branches in
a smarter way?

--
Martin Geisler

Kyle Meyer

unread,
Nov 23, 2016, 9:59:17 AM11/23/16
to Martin Geisler, Magit Maling list
Hello,

Martin Geisler <mar...@geisler.net> writes:

> Hi all,
>
> Does Magit have an option to sort branch names by the order they have
> been used?

No, not that I'm aware of.

>
> I'm using magit-ido-completing-read and as far as I can tell, the
> order of the branches is alphabetically. That is normally not such a
> big problem since typing a few characters narrows the list down.
> However, I recently started having both a "release-2.0" and a
> "release-2.1" branch in my repository -- and now find myself
> repeatedly typing "rel21" to pick the right one :-)
>
> Any hints on how to have the completion function order the branches in
> a smarter way?

Does sorting by the committer date get you the behavior you want?

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index af9134c..7af3975 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -1012,6 +1012,7 @@ (defun magit-list-unmerged-to-upstream-branches ()

(defun magit-list-refnames (&rest args)
(magit-git-lines "for-each-ref" "--format=%(refname:short)"
+ "--sort=-committerdate"
(or args magit-list-refs-namespaces)))

(defun magit-list-branch-names ()
--8<---------------cut here---------------end--------------->8---

If so, you could create a feature request for this to be added as an
option.

--
Kyle

Martin Geisler

unread,
Nov 25, 2016, 3:36:33 AM11/25/16
to Kyle Meyer, Magit Maling list
Hi Kyle,

Yeah, that works really well! Thanks a lot :-)

I've added an issue for it here with your patch:
https://github.com/magit/magit/issues/2872

I hope to submit it as a patch later when I'm home -- but others are
of course free to jump in an do it sooner :-)
--
Martin Geisler
Reply all
Reply to author
Forward
0 new messages