diff --git a/README.md b/README.md index fcd80e79..060d98eb 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,10 @@ Name of the remote branch to link to, defaults to the current branch. If `t` also open the link via `browse-url`. To use an alternate function set to that function's symbol. Defaults to `nil`. +##### `git-link-http-link` + +If `t` use http instead of https in the link. Defaults to `nil`. + ##### `git-link-use-commit` If non-`nil` use the latest commit's hash in the link instead of the branch name, defaults to `nil`. @@ -109,7 +113,7 @@ by [setting `sourcegraph` as the default remote](#settings). **Note** that the remote can be named anything but its URL's host must match what's in the associated link function's alist. This defaults to `"sourcegraph"` but can be changed. See [Building Links and Adding Services](#building-links-and-adding-services). -URLs with ports or an http scheme will not work. It's a trivial fix so if it's a problem for you please open an issue. +URLs with ports will not work. It's a trivial fix so if it's a problem for you please open an issue. ### Building Links and Adding Services diff --git a/git-link-test.el b/git-link-test.el index 5fcac905..92a7b3b8 100644 --- a/git-link-test.el +++ b/git-link-test.el @@ -66,3 +66,19 @@ (should (equal '("go.googlesource.com" "go") (git-link--parse-remote "https://go.googlesource.com/go")))) + +(ert-deftest git-link--parse-remote-http-test () + ;; test https (defaults) + (should (equal "https" + (git-link--link-type))) + + (should (equal "https://hostname/dirname/blob/branch/filename#L7-L11" + (git-link-github "hostname" "dirname" "filename" "branch" "commit" 7 11))) + + ;; test http + (setq git-link-http-link t) + (should (equal "http" + (git-link--link-type))) + + (should (equal "http://hostname/dirname/blob/branch/filename#L7-L11" + (git-link-github "hostname" "dirname" "filename" "branch" "commit" 7 11)))) diff --git a/git-link.el b/git-link.el index d5a6d6d4..d80a8dd8 100644 --- a/git-link.el +++ b/git-link.el @@ -199,6 +199,11 @@ function set to that function's symbol." :type '(choice boolean function) :group 'git-link) +(defcustom git-link-http-link nil + "If t use http instead of https in the link." + :type '(choice boolean function) + :group 'git-link) + (defcustom git-link-use-commit nil "If non-nil use the latest commit's hash in the link instead of the branch name." :type 'boolean @@ -286,6 +291,11 @@ we can prevent that behaviour." :type 'list :group 'git-link) +(defun git-link--link-type () + (if git-link-http-link + "http" + "https")) + (defun git-link--exec(&rest args) (ignore-errors (with-temp-buffer @@ -527,7 +537,8 @@ return (FILENAME . REVISION) otherwise nil." (browse-url link)))) (defun git-link-codeberg (hostname dirname filename branch commit start end) - (format "https://%s/%s/src/%s/%s" + (format "%s://%s/%s/src/%s/%s" + (git-link--link-type) hostname dirname (or branch commit) @@ -539,7 +550,8 @@ return (FILENAME . REVISION) otherwise nil." (format "L%s" start))))))) (defun git-link-gitlab (hostname dirname filename branch commit start end) - (format "https://%s/%s/-/blob/%s/%s" + (format "%s://%s/%s/-/blob/%s/%s" + (git-link--link-type) hostname dirname (or branch commit) @@ -551,7 +563,8 @@ return (FILENAME . REVISION) otherwise nil." (format "L%s" start))))))) (defun git-link-github (hostname dirname filename branch commit start end) - (format "https://%s/%s/blob/%s/%s" + (format "%s://%s/%s/blob/%s/%s" + (git-link--link-type) hostname dirname (or branch commit) @@ -563,7 +576,8 @@ return (FILENAME . REVISION) otherwise nil." (format "L%s" start))))))) (defun git-link-googlesource (hostname dirname filename branch commit start end) - (format "https://%s/%s/+/%s/%s" + (format "%s://%s/%s/+/%s/%s" + (git-link--link-type) hostname dirname (or branch commit) @@ -573,7 +587,8 @@ return (FILENAME . REVISION) otherwise nil." )))) (defun git-link-azure (hostname dirname filename branch commit start end) - (format "https://%s/%s?path=%%2F%s&version=%s&line=%s&lineEnd=%s&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain" + (format "%s://%s/%s?path=%%2F%s&version=%s&line=%s&lineEnd=%s&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain" + (git-link--link-type) hostname dirname filename @@ -582,7 +597,8 @@ return (FILENAME . REVISION) otherwise nil." (or end start ""))) (defun git-link-sourcehut (hostname dirname filename branch commit start end) - (format "https://%s/%s/tree/%s/%s" + (format "%s://%s/%s/tree/%s/%s" + (git-link--link-type) hostname dirname (or branch commit) @@ -594,25 +610,29 @@ return (FILENAME . REVISION) otherwise nil." (format "L%s" start))))))) (defun git-link-commit-gitlab (hostname dirname commit) - (format "https://%s/%s/-/commit/%s" + (format "%s://%s/%s/-/commit/%s" + (git-link--link-type) hostname dirname commit)) (defun git-link-commit-github (hostname dirname commit) - (format "https://%s/%s/commit/%s" + (format "%s://%s/%s/commit/%s" + (git-link--link-type) hostname dirname commit)) (defun git-link-commit-googlesource (hostname dirname commit) - (format "https://%s/%s/+/%s" + (format "%s://%s/%s/+/%s" + (git-link--link-type) hostname dirname commit)) (defun git-link-commit-azure (hostname dirname commit) - (format "https://%s/%s/commit/%s" + (format "%s://%s/%s/commit/%s" + (git-link--link-type) hostname dirname @@ -620,13 +640,15 @@ return (FILENAME . REVISION) otherwise nil." (car (git-link--exec "rev-parse" commit)))) (defun git-link-commit-codeberg (hostname dirname commit) - (format "https://%s/%s/commit/%s" + (format "%s://%s/%s/commit/%s" + (git-link--link-type) hostname dirname commit)) (defun git-link-gitorious (hostname dirname filename _branch commit start _end) - (format "https://%s/%s/source/%s:%s#L%s" + (format "%s://%s/%s/source/%s:%s#L%s" + (git-link--link-type) hostname dirname commit @@ -634,14 +656,16 @@ return (FILENAME . REVISION) otherwise nil." start)) (defun git-link-commit-gitorious (hostname dirname commit) - (format "https://%s/%s/commit/%s" + (format "%s://%s/%s/commit/%s" + (git-link--link-type) hostname dirname commit)) (defun git-link-bitbucket (hostname dirname filename _branch commit start end) ;; ?at=branch-name - (format "https://%s/%s/src/%s/%s" + (format "%s://%s/%s/src/%s/%s" + (git-link--link-type) hostname dirname commit @@ -657,13 +681,15 @@ return (FILENAME . REVISION) otherwise nil." (defun git-link-commit-bitbucket (hostname dirname commit) ;; ?at=branch-name - (format "https://%s/%s/commits/%s" + (format "%s://%s/%s/commits/%s" + (git-link--link-type) hostname dirname commit)) (defun git-link-cgit (hostname dirname filename branch commit start _end) - (format "https://%s/%s/tree/%s?h=%s" + (format "%s://%s/%s/tree/%s?h=%s" + (git-link--link-type) hostname dirname filename @@ -673,7 +699,8 @@ return (FILENAME . REVISION) otherwise nil." (concat "#" (format "n%s" start)))))) (defun git-link-commit-cgit (hostname dirname commit) - (format "https://%s/%s/commit/?id=%s" + (format "%s://%s/%s/commit/?id=%s" + (git-link--link-type) hostname dirname commit)) @@ -698,7 +725,8 @@ return (FILENAME . REVISION) otherwise nil." (t ""))) (branch-or-commit (or branch commit)) (dir-file-name (directory-file-name dirname))) - (format "https://%s/%s@%s/-/blob/%s%s" + (format "%s://%s/%s@%s/-/blob/%s%s" + (git-link--link-type) hostname dir-file-name branch-or-commit @@ -707,18 +735,21 @@ return (FILENAME . REVISION) otherwise nil." (defun git-link-commit-sourcegraph (hostname dirname commit) (let ((dir-file-name (directory-file-name dirname))) - (format "https://%s/%s/-/commit/%s" + (format "%s://%s/%s/-/commit/%s" + (git-link--link-type) hostname dir-file-name commit))) (defun git-link-homepage-github (hostname dirname) - (format "https://%s/%s" + (format "%s://%s/%s" + (git-link--link-type) hostname dirname)) (defun git-link-homepage-savannah (hostname dirname) - (format "https://%s/cgit/%s.git/" + (format "%s://%s/cgit/%s.git/" + (git-link--link-type) hostname dirname)) @@ -729,7 +760,8 @@ return (FILENAME . REVISION) otherwise nil." commit start end) - (format "https://%s/%s/browse/refs/heads/%s/--/%s" + (format "%s://%s/%s/browse/refs/heads/%s/--/%s" + (git-link--link-type) hostname dirname (or branch commit) @@ -740,10 +772,10 @@ return (FILENAME . REVISION) otherwise nil." (or end start)))))) (defun git-link-commit-codecommit (hostname dirname commit) - (format "https://%s/%s/commit/%s" hostname dirname commit)) + (format "%s://%s/%s/commit/%s" (git-link--link-type) hostname dirname commit)) (defun git-link-homepage-codecommit (hostname dirname) - (format "https://%s/%s/browse" hostname dirname)) + (format "%s://%s/%s/browse" (git-link--link-type) hostname dirname)) (define-obsolete-function-alias 'git-link-homepage-svannah 'git-link-homepage-savannah "cf947f9")