Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stash support #34

Merged
merged 2 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions browse-at-remote.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 (string-join (list "?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"
Expand Down
4 changes: 4 additions & 0 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
------
Expand Down