summary refs log tree commit diff
path: root/emacs/elisp/my-git-extra.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/elisp/my-git-extra.el')
-rw-r--r--emacs/elisp/my-git-extra.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/emacs/elisp/my-git-extra.el b/emacs/elisp/my-git-extra.el
new file mode 100644
index 0000000..862286a
--- /dev/null
+++ b/emacs/elisp/my-git-extra.el
@@ -0,0 +1,42 @@
+;;; my-git-extra.el --- Extra functions to work with gitattributes
+;;; Commentary:
+;;; Code:
+
+(require 'magit)
+(require 'git-link)
+
+(defun my/clone-repo (url)
+  "Clone a repository in the workspace using URL."
+  (interactive "sURL:")
+  (let* ((repo-name (magit-clone--url-to-name url))
+         (target-dir (concat  "~/workspace/" repo-name)))
+    (magit-clone-regular url target-dir nil)))
+
+(defun my/get-sg-remote-from-hostname (hostname)
+  "Create a sourcegraph URL from HOSTNAME."
+  (format "sourcegraph.rbx.com/%s" hostname))
+
+(defun my/git-link-work-sourcegraph (hostname dirname filename _branch commit start end)
+  "Create a link to sourcegraph given a HOSTNAME DIRNAME FILENAME _BRANCH COMMIT START and END."
+  ;; Use the default branch of the repository instead of the
+  ;; current one (we might be on a feature branch that is not
+  ;; available on the remote).
+  (let ((sg-base-url (my/get-sg-remote-from-hostname hostname))
+        (main-branch (magit-main-branch)))
+    (git-link-sourcegraph sg-base-url dirname filename main-branch commit start end)))
+
+(defun my/git-link-commit-work-sourcegraph (hostname dirname commit)
+  "Create the link to sourcegraph given a HOSTNAME DIRNAME and COMMIT."
+  (let ((sg-base-url (my/get-sg-remote-from-hostname hostname)))
+    (git-link-commit-sourcegraph sg-base-url dirname commit)))
+
+;; for work related repositories, open them in our instance of sourcegraph
+(add-to-list 'git-link-remote-alist '("github\\.rbx\\.com" my/git-link-work-sourcegraph))
+(add-to-list 'git-link-commit-remote-alist '("github\\.rbx\\.com" my/git-link-commit-work-sourcegraph))
+
+;; for personal code I use gitea, which is similar to codeberg
+(add-to-list 'git-link-remote-alist '("git\\.my\\.net" git-link-codeberg))
+(add-to-list 'git-link-commit-remote-alist '("git\\.my\\.net" git-link-commit-codeberg))
+
+(provide 'my-git-extra)
+;;; my-git-extra.el ends here