Skip to content

Commit 4985941

Browse files
FrostyXYour Name
authored andcommitted
If in magit-revision buffer, git-link can open the commit
I think this better than printing an error that > Can't figure out what to link to When in a `magit-revision` buffer, people most likely want to link the displayed commit. But this also allows to link a commit that the cursor is pointing to.
1 parent d9b375f commit 4985941

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ For example:
163163
<img src="./magit-revision-buffer.png" width="400" alt="magit-revision buffer demo">
164164

165165
Here one can get a link to:
166-
- The commit by calling `git-link-commit` on a commit hash
167166
- A file by calling `git-link` on a filename or within its diff
167+
- The commit by calling `git-link-commit` on a commit hash or anywhere in the
168+
buffer (besides filename or its diff)
168169

169170
### Building Links and Adding Services
170171

git-link.el

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,19 @@ Defaults to \"origin\"."
951951
(if (null remote-url)
952952
(message "Remote `%s' not found" remote)
953953

954+
(setq commit (word-at-point))
955+
(when (and (not (string-match-p "[a-fA-F0-9]\\{7,40\\}" (or commit "")))
956+
(derived-mode-p 'magit-revision-mode))
957+
(setq commit (magit-buffer-revision)))
958+
954959
(setq remote-info (git-link--parse-remote remote-url)
955960
git-host (car remote-info)
956-
commit (word-at-point)
957961
handler (git-link--handler git-link-commit-remote-alist git-host)
958962
web-host (git-link--web-host git-host))
959963

960964
(cond ((null git-host)
961965
(message "Remote `%s' contains an unsupported URL" remote))
962-
((not (string-match-p "[a-fA-F0-9]\\{7,40\\}" (or commit "")))
966+
((not commit)
963967
(message "Point is not on a commit hash"))
964968
((not (functionp handler))
965969
(message "No handler for %s" git-host))

0 commit comments

Comments
 (0)