Created
March 23, 2011 19:01
-
-
Save ieure/883725 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(eval-after-load "magit" | |
'(progn | |
(defun magit-browse-github (commit) | |
"Open a browser pointing to the tracked branch on GitHub. | |
With prefix argument, go to the commit HEAD is at." | |
(interactive "p") | |
(let* ((branch (magit-get-current-branch)) | |
(remote (and branch (magit-get "branch" branch "remote"))) | |
(remote-branch (or (and branch (magit-remote-branch-for branch)) | |
branch)) | |
(remote-url (magit-get "remote" remote "url")) | |
(head (magit-git-string "log" "--max-count=1" | |
"--pretty=format:%h")) | |
(remote-tree (if (> commit 1) head remote-branch))) | |
(browse-url | |
(cond ((string-match "git@github\\.com" remote-url) | |
(replace-regexp-in-string | |
"^[email protected]:\\(.*?\\)\\(\\.git\\)?$" | |
(format "https://github.com/\\1/tree/%s" remote-tree) | |
remote-url)) | |
((string-match "https?://github\\.com" remote-url) | |
(replace-regexp-in-string | |
"^\\(https?://github\\.com/.*?\\)\\(\\.git\\)?$" | |
(format "\\1/tree/%s" remote-tree) remote-url)) | |
(t (error "Tracked branch is not on GitHub.")))))) | |
(define-key magit-mode-map "\C-ch" 'magit-browse-github))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment