summary refs log tree commit diff
path: root/emacs
diff options
context:
space:
mode:
authorFranck Cuny <franck.cuny@gmail.com>2020-07-17 17:04:39 -0700
committerFranck Cuny <franck.cuny@gmail.com>2020-07-17 17:04:39 -0700
commit171bccba73acf8eaed772de8bcece1577b03b05d (patch)
treeddd5ecefa93e5bf18b73927c57bb0c2e654b0dae /emacs
parentzsh: simplify configuration (diff)
downloademacs.d-171bccba73acf8eaed772de8bcece1577b03b05d.tar.gz
emacs: add git-link / support for sourcegraph
We're moving from go/cs (twitter's own code search) to sourcegraph. I'm
adding git-link and the configuration to go from emacs to our
sourcegraph instance.

Doing `git-link` in a file will take me to the file in sg, and doing
`git-link-commit` on a commit in magit will take me to the commit in sg.
Diffstat (limited to '')
-rw-r--r--emacs.d/custom/fcuny-git.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/emacs.d/custom/fcuny-git.el b/emacs.d/custom/fcuny-git.el
index 48409a7..e3b8c45 100644
--- a/emacs.d/custom/fcuny-git.el
+++ b/emacs.d/custom/fcuny-git.el
@@ -28,6 +28,37 @@
     (setq-local fill-column 72)
     (setq-local comment-auto-fill-only-comments nil)))
 
+;; from https://sideshowcoder.com/2020/07/02/opening-sourcegraph-from-emacs/
+;; in a repo, add the following in .git/config:
+;;
+;; [git-link]
+;;        remote = mysourcegraph.sourcegraph
+;; [remote "mysourcegraph.sourcegraph"]
+;;        url = https://sourcegraph.twitter.biz/gitpuppet.twitter.biz/puppet-twitter
+;;
+(use-package git-link
+  :ensure t
+  :config
+  (defun git-link-sourcegraph (hostname dirname filename _branch commit start end)
+    (let ((line-or-range (if end (format "%s-%s" start end) start)))
+      (format "https://%s/%s@%s/-/blob/%s#L%s"
+              hostname
+              dirname
+              commit
+              filename
+              line-or-range)))
+
+  (defun git-link-commit-sourcegraph (hostname dirname commit)
+    (format "https://%s/%s/-/commit/%s"
+            hostname
+            dirname
+            commit))
+
+  (add-to-list 'git-link-remote-alist '("sourcegraph" git-link-sourcegraph))
+  (add-to-list 'git-link-commit-remote-alist '("sourcegraph" git-link-commit-sourcegraph))
+
+  (setq git-link-open-in-browser 't))
+
 ;; https://magit.vc/manual/magit/Per_002dRepository-Configuration.html
 ;; we don't want to refresh buffers in source. This should help with
 ;; performances.