Skip to content

Commit 51d14e9

Browse files
committed
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 51d14e9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
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` or `git-link` on a commit
168+
hash or anywhere in the buffer (besides filename or its diff)
168169

169170
### Building Links and Adding Services
170171

git-link.el

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,10 @@ With a double prefix argument invert the value of
904904
handler (git-link--handler git-link-remote-alist git-host)
905905
web-host (git-link--web-host git-host))
906906

907-
(cond ((null filename)
907+
(cond ((and (derived-mode-p 'magit-revision-mode)
908+
(not (magit-section-match '(file hunk))))
909+
(git-link-commit remote))
910+
((null filename)
908911
(message "Can't figure out what to link to"))
909912
((null git-host)
910913
(message "Remote `%s' contains an unsupported URL" remote))
@@ -951,15 +954,19 @@ Defaults to \"origin\"."
951954
(if (null remote-url)
952955
(message "Remote `%s' not found" remote)
953956

957+
(setq commit (word-at-point))
958+
(when (and (not (string-match-p "[a-fA-F0-9]\\{7,40\\}" (or commit "")))
959+
(derived-mode-p 'magit-revision-mode))
960+
(setq commit (magit-buffer-revision)))
961+
954962
(setq remote-info (git-link--parse-remote remote-url)
955963
git-host (car remote-info)
956-
commit (word-at-point)
957964
handler (git-link--handler git-link-commit-remote-alist git-host)
958965
web-host (git-link--web-host git-host))
959966

960967
(cond ((null git-host)
961968
(message "Remote `%s' contains an unsupported URL" remote))
962-
((not (string-match-p "[a-fA-F0-9]\\{7,40\\}" (or commit "")))
969+
((not commit)
963970
(message "Point is not on a commit hash"))
964971
((not (functionp handler))
965972
(message "No handler for %s" git-host))

0 commit comments

Comments
 (0)