From 846b97155e680fbdc848ee813d7c40415908d252 Mon Sep 17 00:00:00 2001 From: Yauhen Lazurkin Date: Wed, 8 Mar 2017 20:15:16 +0300 Subject: [PATCH 1/2] Add Stash support --- browse-at-remote.el | 26 ++++++++++++++++++++++++-- readme.rst | 4 ++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/browse-at-remote.el b/browse-at-remote.el index c9dac62..3e8451c 100644 --- a/browse-at-remote.el +++ b/browse-at-remote.el @@ -36,7 +36,7 @@ (require 'vc-git) (defgroup browse-at-remote nil - "Open target on github/gitlab/bitbucket" + "Open target on github/gitlab/bitbucket/stash" :prefix "browse-at-remote-" :group 'applications) @@ -180,7 +180,7 @@ If HEAD is detached, return nil." (or (let* ((domain (car target-repo)) (remote-type-from-config (browse-at-remote--get-remote-type-from-config))) - (if (member remote-type-from-config '("github" "bitbucket" "gitlab")) + (if (member remote-type-from-config '("github" "bitbucket" "gitlab" "stash")) remote-type-from-config (cl-loop for pt in browse-at-remote-remote-type-domains when (string= (car pt) domain) @@ -216,6 +216,28 @@ If HEAD is detached, return nil." "Commit URL formatted for bitbucket" (format "%s/commits/%s" repo-url commithash)) +(defun browse-at-remote--fix-repo-url-stash (repo-url) + "Inserts 'projects' and 'repos' in #repo-url" + (let* ((reversed-url (reverse (split-string repo-url "/"))) + (project (car reversed-url)) + (repo (nth 1 reversed-url))) + (string-join (reverse (append (list project "repos" repo "projects") (nthcdr 2 reversed-url))) "/"))) + +(defun browse-at-remote--format-region-url-as-stash (repo-url location filename &optional linestart lineend) + "URL formatted for stash" + (let* ((branch (cond + ((string= location "master") "") + (t (concatenate 'string "?at=refs%2Fheads%2F" location)))) + (lines (cond + (lineend (format "#%d-%d" linestart lineend)) + (linestart (format "#%d" linestart)) + (t "")))) + (format "%s/browse/%s%s%s" (browse-at-remote--fix-repo-url-stash repo-url) filename branch lines))) + +(defun browse-at-remote--format-commit-url-as-stash (repo-url commithash) + "Commit URL formatted for stash" + (format "%s/commits/%s" (browse-at-remote--fix-repo-url-stash repo-url) commithash)) + (defun browse-at-remote--format-region-url-as-gitlab (repo-url location filename &optional linestart lineend) "URL formatted for gitlab. The only difference from github is format of region: L1-2 instead of L1-L2" diff --git a/readme.rst b/readme.rst index b2cd7cc..e97b397 100644 --- a/readme.rst +++ b/readme.rst @@ -33,6 +33,10 @@ If your repository is hosted on GitHub enterprise, you should add following sett git config --add browseAtRemote.type "github" +For private Stash repitory use command::: + + git config --add browseAtRemote.type "stash" + Usage: ------ From 4a85f9b01085489934edb5850bd1fc0a07cde521 Mon Sep 17 00:00:00 2001 From: Yauhen Lazurkin Date: Thu, 9 Mar 2017 13:04:57 +0300 Subject: [PATCH 2/2] Replace concatenate with string-join --- browse-at-remote.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browse-at-remote.el b/browse-at-remote.el index 3e8451c..206f339 100644 --- a/browse-at-remote.el +++ b/browse-at-remote.el @@ -227,7 +227,7 @@ If HEAD is detached, return nil." "URL formatted for stash" (let* ((branch (cond ((string= location "master") "") - (t (concatenate 'string "?at=refs%2Fheads%2F" location)))) + (t (string-join (list "?at=refs%2Fheads%2F" location))))) (lines (cond (lineend (format "#%d-%d" linestart lineend)) (linestart (format "#%d" linestart))