From 1efde9202ce712495ed7010fac1c172be90d8b94 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 24 Jun 2010 15:56:54 -0700 Subject: [PATCH] Filter out HEAD refs from magit-name-rev. HEAD refs are nasty because they're highly contingent. Branches, tags, and remotes all require some commit to be made in order for the ref to point to a different rev, but HEADs just need something else to be checked out. Also, filtering out HEADs makes the name more portable. This is useful for Magithub, where the name may be passed on to GitHub. --- magit.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/magit.el b/magit.el index 5e4863d4..81aaaee4 100644 --- a/magit.el +++ b/magit.el @@ -521,9 +521,23 @@ return nil." (defun magit-name-rev (rev) "Return a human-readable name for REV. Unlike git name-rev, this will remove tags/ and remotes/ prefixes -if that can be done unambiguously." +if that can be done unambiguously. In addition, it will filter +out revs involving HEAD." (when rev (let ((name (magit-git-string "name-rev" "--no-undefined" "--name-only" rev))) + ;; There doesn't seem to be a way of filtering HEAD out from name-rev, + ;; so we have to do it manually. + ;; HEAD-based names are too transient to allow. + (when (string-match "^\\(.*\\" name)) + (setq name (magit-rev-parse ref))))) (setq rev (or name rev)) (when (string-match "^\\(?:tags\\|remotes\\)/\\(.*\\)" rev) (let ((plain-name (match-string 1 rev)))