Skip to content

Instantly share code, notes, and snippets.

@hanabokuro
Created December 12, 2013 06:52
Show Gist options
  • Save hanabokuro/7924089 to your computer and use it in GitHub Desktop.
Save hanabokuro/7924089 to your computer and use it in GitHub Desktop.
get url from magit log
(defun dev-gitweb-diff-url-from-magit ()
(interactive)
(let* (
(branch (magit-get-current-branch))
(remote (and branch (magit-get "branch" branch "remote")))
(remote-rebase (and branch (magit-get-boolean "branch" branch "rebase")))
(remote-branch (or (and branch (magit-remote-branch-for branch)) branch))
(remote-string (and remote remote-branch (magit-remote-string remote remote-branch remote-rebase)))
(remote-url (and remote (magit-get "remote" remote "url")))
(git-root (and (buffer-file-name) (magit-get-top-dir (file-name-directory (buffer-file-name)))))
(commit-from (magit-git-string "rev-list" "HEAD" "--max-count=1"))
(commit-to (magit-commit-at-point))
(gitweb-url (and remote-url remote-branch
(concat (replace-regexp-in-string "\\.git$" "" (replace-regexp-in-string "^\\(ssh://\\)?git@\\([^:/]+\\)[:/]" "http://\\2?p=" remote-url)) ".git"
";a=commitdiff"
"&h=" commit-from
"&hp=" commit-to
)))
)
gitweb-url
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment