Compare commits

...

175 commits

Author SHA1 Message Date
Adrian Miranda 63c0e77aaf
fix: handle browser paths safely (#234)
Some checks failed
CI / basics (push) Has been cancelled
2026-05-24 21:06:15 -04:00
Prabhu Jayakumar 41ebfcebe1
Add support for bitbucket repos cloned with ssh (#174) 2026-02-24 08:09:33 -08:00
Sam Saccone f4832493a0
tests: add test for open.default.remote configuration (#226)
Co-authored-by: Sam Bo <agent@openclaw.ai>
2026-02-14 07:21:58 -08:00
Simon Olofsson 477b196a1d
README: Add Bash section for Oh-My-Bash (#214) 2026-01-14 12:57:31 -08:00
sixther a223125abc
Added support for cnb.cool. (#217)
Co-authored-by: ericdduan <ericdduan@tencent.com>
2025-03-19 12:07:49 -07:00
Rob Loach 2a66fcd7e3
Add oh-my-bash support (#213)
Some checks failed
CI / basics (push) Has been cancelled
2024-10-03 18:17:24 -07:00
Paul Irish ce881820db make shellcheck happy. #170
Some checks failed
CI / basics (push) Has been cancelled
2024-08-05 17:08:25 -07:00
Paul Irish a7d09090c2 add a test for new --file option. ref #170 2024-08-05 17:06:40 -07:00
Paul Irish 866c39dbf4 add npmignore to avoid publishing bats-assert/support 2024-08-05 16:57:16 -07:00
Paul Irish 64cf066704 3.1.0 2024-08-05 16:54:16 -07:00
Paul Irish a437297494 package: repo fix 2024-08-05 16:54:03 -07:00
Brian Wellington dd22397400
Add --file option. (#170) 2024-08-05 16:52:18 -07:00
Sandro 5d1f938b47
Use absolute PATH to powershell.exe (#204)
Some checks failed
CI / basics (push) Has been cancelled
2024-07-05 07:03:11 -07:00
Majid Alaeinia d086ab0077
readme: zsh: Consider sourcing ~/.zshrc (#209) 2024-02-21 11:26:09 -08:00
Sandro 281dad270e
Add gitea support (#184) 2023-05-02 11:29:10 -07:00
Paul Irish f772364eb8 adjust http preservation test 2022-07-18 15:29:03 -07:00
Paul Irish 17491478e6 3.0.0 2022-07-18 15:17:02 -07:00
Paul Irish 0b626514bb
move to github actions (#192) 2022-07-18 14:19:56 -07:00
Paul Irish 1a93477f70 update dependencies 2022-07-18 13:30:29 -07:00
Sowmiya M f11ced9a4f
Remove unused code and fix double-negation (#153) 2022-07-18 13:30:13 -07:00
Paul Irish 0b6b0a2b40 package-lock.json update 2022-07-18 13:10:50 -07:00
ratijas ca0214c0d6
Fix broken links in changelog (#172) 2022-07-18 12:46:58 -07:00
kazufusa 8ac94bf7c3
gitlab: fix issue ID parsing (#183) 2022-07-18 12:46:28 -07:00
John Meyer 0296983a28
WSL: do not load PowerShell profile (#190) 2022-07-18 12:37:31 -07:00
Dave Wikoff 14fdf5c96e Merge branch 'pull-165' into master 2020-08-21 15:09:30 -07:00
Dave Wikoff ca8b2348f2 Fix bitbucket tests 2020-08-21 15:02:54 -07:00
Heechul Ryu c908a50824 Delete the comment for issue #80 2020-07-08 11:10:29 +01:00
Heechul Ryu 0189caeb4b Open bitbucket with the right branch
replace from `?at` to `/` for `providerBranchRef`
2020-07-08 11:10:29 +01:00
Dave Wikoff 3e8c908dcd
Merge pull request #166 from glostis/fix-suffix
Fix suffix with `=` in it
2020-07-07 14:46:30 -07:00
Guillaume Lostis 3bd3524de2 Fix shellcheck 2020-06-19 14:02:31 +02:00
Guillaume Lostis 1d55c4ee50 Fix formatting to pass shellcheck 2020-06-19 12:35:48 +02:00
Guillaume Lostis 91170cd5c8 Fix handling of suffix with = in it 2020-06-19 12:11:53 +02:00
Guillaume Lostis 9a35780c09 Add test for suffix with = in it 2020-06-19 12:11:29 +02:00
Dave Wikoff d9a0d19ce2
Merge pull request #149 from rec/documentation
Document flags to git-open
2019-12-22 13:55:37 -05:00
Dave Wikoff 849298fece
Detect WSL case insensitively (#158)
Detect WSL case insensitively
2019-12-22 13:32:17 -05:00
Víctor ad8fac9309
Detect WSL case insensitively
My `uname -r` is `4.19.81-microsoft-standard`
2019-11-26 10:54:37 +01:00
Frank Fesevur fcbbf918f7
Merge pull request #154 from dineshba/master
Add suffix flag
2019-09-16 07:56:38 +02:00
Dinesh 8b909f81dc Add suffix flag
Co-authored-by: Sowmiya <sowmiyamuthuraman@gmail.com>
2019-09-07 23:08:13 +05:30
Tom Ritchford d52366d8c9 Document flags to git-open 2019-07-29 15:18:33 +02:00
Dave Wikoff 08fa2abd7e
Add a --commit option (#144)
Add a --commit option
2019-07-09 12:21:32 -04:00
Domenico Gemoli 0564817aef Adding a --commit option.
I've only tested this with gitlab seeing as I needed it there. If this could be useful I can integrate any feedback you might have to get this proposal merged.
2019-07-08 23:34:13 +02:00
Dave Wikoff 44382bf541
Merge pull request #143 from arunvelsriram/print-option
Add option to print the url
2019-07-06 13:17:10 -04:00
Arunvel Sriram 8239d0a785 Add option to print the url 2019-07-03 21:32:34 +05:30
Dave Wikoff 7eeee771ce
default to upstream branch (#140)
default to upstream branch
2019-06-02 13:35:38 -04:00
Love F 3d1ad212b2 default to upstream branch 2019-06-02 14:24:41 +02:00
Paul Irish 4eed00f282
Fix shellcheck on travis (#134) 2018-12-03 18:24:29 -08:00
Paul Irish 556dbe91f2
readme: add 2.1.0 release to mini changelog 2018-12-03 11:09:06 -08:00
Paul Irish 5344a73106 -> v2.1.0 2018-12-03 10:59:46 -08:00
Paul Irish 5eba420570 npm audit fix 2018-12-03 10:55:18 -08:00
Paul Irish f02d7e97b0 add package-lock.json 2018-12-03 10:55:18 -08:00
Dave Wikoff 301c5a619e
Merge pull request #132 from neersighted/patch-1
Remove openopt, allow spaces in $BROWSER
2018-11-22 20:11:25 -05:00
Bjorn Neergaard 96c80ffe80 Remove openopt, allow spaces in $BROWSER
Remove the openopt variable, instead opting to allow spaces in `$BROWSER`.

`$BROWSER` as used by the XDG implementation allows spaces (and `%s`
printf-style formatting strings), and is actually a PATH-style list.
While this patch doesn't make git-open compliant with the XDG-style
variable, it does allow for the use of `BROWSER="powershell.exe
Start"` in the environment.
2018-11-21 14:01:33 -07:00
Dave Wikoff 4ca19904a2
Merge pull request #130 from orestisf1993/tags-commits
Support opening current tag / commit
2018-09-17 11:08:39 -04:00
Orestis Floros 8c8c41bd50
Support opening current tag / commit
Fixes #89.
Fixes #129.
2018-09-14 05:28:58 +03:00
Dave Wikoff 5fefffede3
Merge pull request #128 from crossroad0201/master
Supports AWS Code Commit.
2018-08-16 17:49:40 -04:00
Y.Tsuji 6bb49c28c5 Fix Indentation. 2018-08-13 01:55:43 +09:00
Yohei TSUJI c5e636f423 Append 'AWS Code Commit' to supported remote repositories. 2018-08-10 15:56:39 +09:00
Yohei TSUJI 2ef17f07d8 Added test cases for AWS Code Commit. 2018-08-10 15:56:21 +09:00
Yohei TSUJI c68b9c16e8
Merge pull request #1 from crossroad0201/supports_aws_code_commit
Added support for AWS Code commit.
2018-08-08 14:20:13 +09:00
Yohei TSUJI 557fd40b1c Added support for AWS Code commit. 2018-08-08 13:58:57 +09:00
Dave Wikoff 995e91591f Swap uppercase/lowercase for ssh feature (#123) 2018-04-29 17:31:30 -07:00
Dave Wikoff d24f64da48
Merge pull request #122 from derimagia/uppercase-bash-3
Fix issue #121 - incompatability with bash < 4
2018-04-27 10:23:50 -04:00
Dave Wikoff 895240ff03 Fix issue #121 - incompatability with bash < 4 2018-04-27 10:19:56 -04:00
Paul Irish 4b1e8601a7
Merge pull request #120 from 4U6U57/119-fix-markdownlint
Fixes markdownlint for build
2018-02-26 23:44:28 -08:00
August Valera c3fd9a48df Revert gitignore package-lock, fix #115
Remove package-lock.json from gitignore for npm
Fix bug in #115 that modified user's gitconfig when running tests
2018-02-26 22:15:35 -08:00
August Valera 5b815cb619 Fix current errors in Markdown files
Also: add package-lock.json to gitignore
Remove prefix $ for commands in the manpage, hope people aren't angry
Add MD034 to markdownlint ignore (bare links, which are helpful for the
manpage)
2018-02-24 22:00:30 -08:00
August Valera 702b8a6fc6 Change dependency markdownlint to markdownlint-cli
markdownlint-cli is the recommended cli for the markdownlint package
See https://www.npmjs.com/package/markdownlint#related

Unit tests should now fail due to markdownlint actually linting md files
2018-02-24 21:50:18 -08:00
Dave Wikoff d049d441b3
Merge pull request #114 from Jaxwood/master
Fix bug with open -i on default VSTS project repo
2018-02-21 20:37:32 -05:00
Jacob Lorenzen aea6e3edb7
Add comment on default VSTS repository urls 2018-02-20 18:20:01 +01:00
Dave Wikoff d9b958087d
Merge pull request #109 from 4U6U57/master
Support domain expansion from sshconfig
2018-02-19 15:06:32 -05:00
August Valera 775361b509 Fix shellcheck 2018-02-15 22:23:37 -08:00
August Valera 8909a2b753 Adds support for sshconfig expansion
See `man ssh_config` for documentation for sshconfig.
Only works on SCP-like remote URL's [user@]hostalias:path/to/repo.git
Parses through ~/.ssh/config, looking for a Host entry matching
hostalias (bash-like pattern matching supported) and expanding it to the
corresponding HostName entry, if applicable.
2018-02-04 12:12:48 -08:00
Dave Wikoff 7449bfa7e1
Merge pull request #115 from larsks/feature/ls-url
Use ls-remote --get-url to get remote url
2018-02-04 12:06:54 -05:00
Dave Wikoff beebcdbf37
Merge pull request #113 from nwinkler/bb-server-context
Bitbucket Server Root Context
2018-02-04 11:32:28 -05:00
Lars Kellogg-Stedman 740222babf Use ls-remote --get-url to get remote url
As noted in a comment, 'git ls-remote --get-url' will expand insteadOf
mappings.  I use a number of shortcuts (like gh: for git on github,
lp: for git on launchpad, me: for my github repositories, etc), so I
was constantly hitting situations in which git-open would fail to do
the right thing.

It looks like '--get-url' has been available since git 2.12.0.
2018-02-02 10:41:54 -05:00
Jacob Lorenzen 67b72ac0f2 Fix bug with open -i on default VSTS project repo
The default VSTS clone url is different from other project repository urls

e.g. Default repository url: https://gitopen.visualstudio.com/_git/Project
     Sibling repository url: https://gitopen.visualstudio.com/Project/_git/Repository

     Trying to use git open -i on the default repository will lead to an
     url formatted as https://gitopen.visualstudio.com/_git/Project/_workitems?id=xx
     This url is malformed as the _git part should not be part of it.

     This change will fix this bug and correctly format url as
     https://gitopen.visualstudio.com/Project/_workitems?id=xx.
2018-01-24 13:41:02 +01:00
Dave Wikoff 51caa23c63
Merge pull request #110 from ffes/add-man-page
Add man page
2018-01-22 11:08:08 -05:00
Nils Winkler 140edbbcee Fixed test names to match existing tests
Also removed some duplicated tests that were introduced during a
previous merge.
2018-01-11 08:18:42 +01:00
Nils Winkler 119ada7f69 Removed an unnecessary if statement 2018-01-10 07:53:44 +01:00
Nils Winkler 24dd2fc5fc Added support for Bitbucket Server with different root context
Please see the unit tests for more details. Basically, take the context
parts before 'scm' and add them to the new URL before the other parts.

Instead of taking fixed indexes for the path elements, base everything
off the index of the found 'scm' path element.
2018-01-09 09:21:01 +01:00
Frank Fesevur ed3a6d0f4d Various improvements as suggested in #110 2017-12-28 00:04:52 +01:00
Dave Wikoff 8caa9ad1da
Merge pull request #112 from felixmosh/master
One-liner install for oh-my-zsh
2017-12-22 11:00:09 -05:00
Felix Mosheev 29434cd76e One liner install for oh-my-zsh 2017-12-21 17:36:23 +02:00
Frank Fesevur ade7ae1595 Add man page 2017-12-03 22:33:45 +01:00
Paul Irish 170159c345
New demo GIF for the readme (#108) 2017-12-01 15:14:49 -08:00
Paul Irish 2ade70e717 readme: changelog bump for 2.0 - breaking change about config. 2017-12-01 14:29:39 -08:00
Paul Irish 4173f3dea4 v2.0.0 2017-12-01 14:27:11 -08:00
Paul Irish 7cf058d1bf readme: changelog bump for 2.0 2017-12-01 14:27:02 -08:00
Paul Irish cdfb1cb05c
readme: refactor Configuration section (#107) 2017-12-01 14:23:41 -08:00
Paul Irish b526edced1
readme: changelog updates 2017-12-01 14:17:33 -08:00
Paul Irish f0bcdd200a
update readme for (gitlab) config (#99) 2017-12-01 13:41:45 -08:00
Frank Fesevur 734517991a Update support for open.default.remote config (#79) 2017-12-01 13:41:32 -08:00
Frank Fesevur d97b7f36aa Fix BATS testing on WSL (#104)
The $openopt resulted in unexpected results during testing
2017-12-01 12:30:50 -08:00
Paul Irish 3a423e11a6
allow command to be run in git repo subdirectory (#105) 2017-12-01 12:18:07 -08:00
Edward Thomson e3ce014bfa Add support for Visual Studio Team Services and Team Foundation Server (#93)
* Parse remotes as URLs or SCP-style paths

Instead of trying to strip on ':' and '/' to simplify a URL, actually
switch based on whether the remote path is a URL ("scheme://host:port/path")
or an SCP-style path (user@host:path) and parse them separately.

This allows us to handle custom ports in HTTP and HTTPS, but ignore
custom ports in an SSH url and HTTP remotes, instead of always upgrading
them to HTTPS.

* Introduce tests for Visual Studio Team Services

Add tests for Visual Studio Team Services (VSTS) and Team Foundation
Server (TFS).  VSTS suggests remote paths in two formats: HTTPS URLs
or SSH URLs (including port number).  TFS is an on-premises product
which - when running as an HTTP endpoint - defaults to port 8080.

* Branch selection in Visual Studio Team Services

VSTS and TFS URLs end in '/_git/RepositoryName` (with 0 or more leading
folders of hierarchy in front of that.)  Detect these from the `_git` in
the penultimate folder of the path.  Append branch information to VSTS
and TFS URLs.

Since VSTS and TFS use a query string to select a branch, instead of
including it in the server path, the `providerBranchRef` for other
services was changed to include the leading `/`, and now the `openurl`
and `providerBranchRef` are simply concatenated, to avoid an incorrect
trailing `/` for the VSTS and TFS branch URLs.

* Issues for Visual Studio Team Services

Provide issue support for VSTS and TFS, modifying the URL from the
`_git` endpoint to the `_workitems` endpoint and appending the `id`
query string.

* README: add VSTS and TFS support
2017-11-30 16:23:52 -08:00
Love F 363d054386 Git styled -h and --issue options (#94) 2017-10-31 16:15:50 -07:00
Frank Fesevur 80cb34169a Add support for WSL (#101) 2017-10-30 16:28:39 -07:00
Paul Irish 07d75b2e1e
add test for bitbucket server (#83)
* add test for bitbucket server
* add branch test for bb server.
* updated assertions from discussion.
* remove 'git/' from test cases
2017-10-27 14:18:02 -07:00
Paul Irish 3e237d4006 v1.5.0 2017-10-27 14:13:23 -07:00
Paul Irish fa49deeb17
default to tracked remote (#88) 2017-10-27 13:56:29 -07:00
Paul Irish f3dbce975f
readme tweaks 2017-10-27 13:49:30 -07:00
Alex Rock Ancelet a15d53b6a8 Add windows doc for non-powershell users (#97) 2017-10-26 15:00:31 -07:00
Dave Wikoff e68eee6a44 Strip ports based on protocol properly. Adding config for custom domains and protocols. (#92) 2017-10-26 12:52:33 -07:00
Marko Kunic c2654071a6 replace Oh-My-Zsh git clone url in README.md (#98) 2017-10-26 12:49:07 -07:00
Frank Fesevur 3be1c00f36 Fix opening final URL on MSYS (#91) 2017-06-23 13:49:00 -07:00
Frank Fesevur daa19636c6 Add license file (#90)
The project is licensed under MIT, but that is quite hidden
in the README. Adding a LICENSE files makes it more visible.
2017-06-23 06:51:58 -07:00
Paul Irish 0a43af82ab skip failing tests temporarily. see #87 2017-06-21 13:27:34 -07:00
Paul Irish 15421e8fb4 readme: fix echo mode note 2017-06-21 10:25:22 -07:00
Paul Irish fd2258f77b readme: npm run unit for unit tests 2017-06-21 10:23:34 -07:00
Paul Irish c9ba476e71 fix shellcheck failure https://github.com/koalaman/shellcheck/wiki/SC2004 2017-06-21 10:19:31 -07:00
Paul Irish 06b74c4821 update test expectations 2017-06-21 10:04:55 -07:00
Paul Irish 494c54e1c6 test: safety check to confirm we're in the sandbox repo. 2017-06-20 18:42:38 -07:00
Paul Irish 2bb36a36cd git open issue: add assertion 2017-06-20 18:03:36 -07:00
Dave Wikoff 79501d6f11 Add issues support 2017-06-20 18:02:52 -07:00
Paul Irish 75ced59719 Merge branch 'master' into rewrite 2017-06-20 17:59:19 -07:00
Frank Fesevur 3f1d4e84b6 Not necessary anymore to skip the test 2017-06-20 17:57:52 -07:00
Paul Irish 73b460f582 add 'npm run unit' for bats tests. 2017-06-20 17:49:44 -07:00
Paul Irish 21d370175d add tests for gitlab: ssh://git@host:port origin (#82) 2017-06-18 17:47:46 -07:00
Paul Irish 53e91d130b export BROWSER variable, and test that its set. 2017-06-18 17:14:31 -07:00
Dave Wikoff c2c7830514 Bitbucket server, and minor tweaks to BROWSER 2017-06-18 16:52:12 -07:00
Paul Irish fd8b0aa991 sandboxrepo: set origin url differently for git 2.12.1? 2017-06-18 16:43:54 -07:00
Paul Irish e4970897f8 update test expectations 2017-06-18 13:53:43 -07:00
Paul Irish 9e9fee04de import revised git-open from @dermagia
62e17bfcb9/config/zsh/bin/git-open
2017-06-18 13:51:53 -07:00
Paul Irish fbc508a940 add issue_template 2017-06-18 13:43:58 -07:00
Paul Irish b449cd0cbc Add BB sourceview tests from PR #26 (#81) 2017-06-18 13:38:43 -07:00
Paul Irish 42a4a0ee70 v1.3.1 2017-06-16 16:04:16 -07:00
Paul Irish 628d75faa8 readme: travis badge and changelog bump
[skip ci]
2017-06-16 16:02:52 -07:00
Paul Irish 927517adb9 Add a test suite (#78) 2017-06-16 15:57:49 -07:00
Frank Fesevur 661a4cb20b Merge pull request #76 from xasx/gitlab-urls
Normalize ssh+port URLs to match default style
2017-06-16 08:58:32 +02:00
Andreas Schoeneck ac027a8d00 Normalize ssh+port URLs to match default style
This will make `ssh://git@<host>:<port>/<user>/<repo>` URLs
intermediately look like `git@<host>:<user>/<repo>` and
expose these to further processing/substitution.

Properties required for proper working are:
* `gitopen.gitlab.domain`
* `gitopen.gitlab.ssh.port`
2017-06-12 12:56:31 +02:00
Frank Fesevur 054772bed6 Fix trailing spaces
CI checks because of it
Leftover of #63
2017-06-01 13:01:34 +02:00
Frank Fesevur cf2c289692 Merge pull request #63 from freekmurze/master
Handle GitHub urls without the git user
2017-05-31 20:55:35 +02:00
Paul Irish abd822a486 Merge pull request #74 from paulirish/shellcheck
Add Shellcheck to CI tests
2017-05-29 12:47:11 -07:00
Paul Irish 92dc862c02 correct shellcheck issues. 2017-05-29 12:41:01 -07:00
Paul Irish 33f34fa516 run shellcheck in CI 2017-05-29 12:37:35 -07:00
Paul Irish 75c61f13e6 Add eclint to assert editorconfig settings (#72) 2017-05-29 12:34:10 -07:00
Paul Irish d2147824ec add travis config (#73) 2017-05-29 12:28:48 -07:00
Frank Fesevur 6da04ca3bc Add EditorConfig file (#70) 2017-05-29 12:11:49 -07:00
Trent Rand 176f1b8f96 Remove username from <giturl> for BitBucket (#69)
The username prefix ‘username@bitbucket.org/*’ caused a phishing error
on Safari which persisted across page visits on BitBucket, unless the
username was manually deleted from url.
2017-05-26 19:16:03 -07:00
Gilad Peleg 1abbb405f9 Correct usage for new versions of zplug (#66) 2017-04-23 08:21:59 -07:00
Paul Irish 305629b0af 1.3.0 2017-02-10 16:22:43 -08:00
Martin Delille 4e3aa0ad51 Add http protocol for Gitlab custom host (#60)
* Add http protocol for Gitlab custom host

* default to https

* Revert "default to https"

This reverts commit b25190b5d1.

* Revert "Merge branch 'master' into http"

This reverts commit 18573f8b29, reversing
changes made to 88a9e254ae.

* Revert "Revert "Merge branch 'master' into http""

This reverts commit fa0e6d1f21.

* Revert "Revert "default to https""

This reverts commit d754476010.
2017-02-10 09:13:47 -08:00
Freek Van der Herten e7dc5562b7 Handle GitHub urls without the git user
In my ssh config if specified that all connections with github.com should use the `git` user. So when cloning a repo I can type:
```bash
git clone github.com:paulirish/git-open.git
``` 
instead of
```bash
git clone git@github.com:paulirish/git-open.git
``` 

This PR contains a fix for repos that have been cloned without specifying the `git` user.
2017-01-04 16:03:51 +01:00
Paul Irish bbc50d7018 v1.2.0 2017-01-03 16:27:40 -08:00
Paul Irish 197648315b Merge pull request #56 from elim/feature/separate-url-gitlab
Supports separate URLs in the repo and the web
2017-01-03 16:19:24 -08:00
Takeru Naito 8ce4938097
Add an explanation of options for GitLab 2016-11-21 20:10:21 +09:00
Takeru Naito 7ac4f71f42
Change the option names for GitLab 2016-11-19 23:03:57 +09:00
Paul Irish 70e7399140 Merge pull request #57 from b4b4r07/change-exit-code
Changed to be exit code when that command is finished
2016-11-12 17:55:13 -08:00
b4b4r07 cb4d833644 Replace exit 0 with exit $? 2016-11-13 01:51:40 +09:00
Takeru Naito 1808e612c5
Supports separate URLs in the repo and the web
On a GitLab server.

ex.
---

repo: git@git.example.com:namespace/project.git
web:  https://gitlab.example.com/namespace/project

$ git config gitopen.gitlab.domain gitlab.example.com
$ git config gitopen.gitlab.ssh-domain git.example.com
$ git open
2016-11-04 19:03:51 +09:00
Paul Irish ce8fb12532 Merge pull request #55 from ffes/gitlab-ssh
Handle GitLab's default SSH notation
2016-11-02 22:54:08 -07:00
Frank Fesevur 36f9a77956 Handle GitLab's default SSH notation
On GitLab the default SSH style is like git@gitlab.example.com:user/repo
Now it recognizes this format as well on your own GitLab installation.
2016-10-27 14:01:14 +02:00
Paul Irish 485bb31427 Merge pull request #51 from evoactivity/patch-1
Handle gitlab using SSH remote URL
2016-08-15 19:39:55 -07:00
Paul Irish afd7fee2b2 Merge pull request #49 from neoascetic/patch-1
Fix gist opening
2016-08-15 19:26:09 -07:00
Liam Potter 6f07f14de5 Handle gitlab using SSH remote URL
You need to add another config option to remove the port, but this is now working for me. Could be improved by adding an option for the protocol as well, I'm using `http` instead of `https`, I've left that as is for now though.
2016-08-15 13:19:17 +01:00
David O'Trakoun 6bba8cb0cd Merge pull request #50 from karlhorky/pedantic-uppercasing
Pedantically uppercase characters
2016-08-12 15:56:29 -04:00
Karl Horky abc2c0aa26 Pedantically uppercase characters 2016-08-12 18:56:55 +02:00
Pavel Puchkin 730aea638e Fix gist opening 2016-08-12 09:50:18 +03:00
Paul Irish a6902ab5cc
1.1.1 2016-08-11 23:46:22 -07:00
Paul Irish 9851542371
use local binaries for tests. 2016-08-11 23:44:39 -07:00
Paul Irish 9d536d85b8 Merge pull request #48 from kyuden/standard_error
Use Standard error output
2016-08-11 23:44:24 -07:00
kyuden 2f190289a4 Output as standard error 2016-08-12 03:05:29 +09:00
kyuden e93db94020 Exit as naming error about branch of issue 2016-08-12 02:56:41 +09:00
Paul Irish 76193236a2 readme rejiggle 🏋 2016-08-05 15:47:41 -07:00
Paul Irish 2523ce5db1 readme: open issue wording tweak 2016-08-05 15:40:14 -07:00
kangaroo5383 c5ec7264a8 Easily track and open the relevant github issue via branch naming convention (#46)
* Open issue using ‘git open issue’
* Update doc to reflect new functionality
2016-08-05 15:38:03 -07:00
Paul Irish 0b414e8b1d readme: related projects 2016-08-05 14:28:42 -07:00
Paul Irish 9b6b3d2ab2 readme: npm package is up to date 2016-08-05 11:27:05 -07:00
Paul Irish aa4aac688f Merge pull request #45 from karstenmueller/master
added windows powershell
2016-08-05 08:02:22 -07:00
Karsten Müller b7891d5e3a added windows powershell 2016-08-05 15:14:59 +02:00
David O'Trakoun f97f28e6fe
alternates 2016-07-23 12:55:10 -04:00
David O'Trakoun 556f1c3f74
Merge branch 'master' of github.com:paulirish/git-open 2016-07-23 12:49:22 -04:00
David O'Trakoun ee5d185c50
changelog 2016-07-23 12:49:14 -04:00
David O'Trakoun d14f3e1ebc Merge pull request #44 from davidosomething/omz-dash-naming
stick to dashed plugin name for OMZ install
2016-07-23 12:47:32 -04:00
David O'Trakoun ced130f13d
stick to dashed plugin name for OMZ install 2016-07-23 12:46:34 -04:00
18 changed files with 6831 additions and 143 deletions

11
.editorconfig Normal file
View file

@ -0,0 +1,11 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

33
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,33 @@
name: CI
on:
push:
branches: [master]
pull_request: # run on all PRs, not just PRs to a particular branch
jobs:
basics:
runs-on: ubuntu-latest
steps:
- name: git clone
uses: actions/checkout@v3
with:
fetch-depth: 100
- uses: actions/setup-node@v3
with:
node-version: latest
- run: npm ci
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 0.4.0 # This is the version i have locally. looks like an upgrade is in order, though…
- run: git submodule update --init
name: pull in bats assertion libs
- run: npm run lint
- run: npm run shellcheck
- run: npm run unit

2
.gitignore vendored
View file

@ -1 +1,3 @@
node_modules/
sandboxrepo
git-open.1

6
.gitmodules vendored Normal file
View file

@ -0,0 +1,6 @@
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/ztombol/bats-assert
[submodule "test/test_helper/bats-support"]
path = test/test_helper/bats-support
url = https://github.com/ztombol/bats-support

5
.npmignore Normal file
View file

@ -0,0 +1,5 @@
node_modules/
sandboxrepo
git-open.1
bats-assert
bats-support

22
LICENSE.md Normal file
View file

@ -0,0 +1,22 @@
MIT License
===========
Copyright (c) 2013-2017 Jason McCreary, Paul Irish and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

177
README.md
View file

@ -1,40 +1,85 @@
# git-open
# git-open [![Build Status](https://img.shields.io/travis/paulirish/git-open/master.svg)](https://travis-ci.org/paulirish/git-open)
Type `git open` to open the GitHub page or website for a repository in your
browser.
Type `git open` to open the repo website (GitHub, GitLab, Bitbucket) in your browser.
![Demo of git open in action](https://user-images.githubusercontent.com/39191/33507513-f60041ae-d6a9-11e7-985c-ab296d6a5b0f.gif)
## Usage
git open [remote-name] [branch-name]
```sh
git open [remote-name] [branch-name]
# Open the page for this branch on the repo website
git open --commit
git open -c
# Open the current commit in the repo website
git open --issue
git open -i
# If this branch is named like issue/#123, this will open the corresponding
# issue in the repo website
git open --print
git open -p
# Only print the url at the terminal, but don't open it
```
(`git open` works with these [hosted repo providers](#supported-remote-repositories), `git open --issue` currently only works with GitHub, Visual Studio Team Services and Team Foundation Server)
### Examples
$ git open
> open https://github.com/REMOTE_ORIGIN_USER/CURRENT_REPO/tree/CURRENT_BRANCH
```sh
$ git open
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
$ git open upstream
> open https://github.com/REMOTE_UPSTREAM_USER/CURRENT_REPO/tree/CURRENT_BRANCH
$ git open someremote
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
$ git open upstream master
> open https://github.com/REMOTE_UPSTREAM_USER/CURRENT_REPO/tree/master
$ git open someremote somebranch
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/PROVIDED_BRANCH
![git open2015-01-24 13_51_18](https://cloud.githubusercontent.com/assets/39191/5889192/244a0b72-a3d0-11e4-8ab9-55fc64228aaa.gif)
$ git open --issue
# If branches use naming convention of issues/#123,
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123
### Installation
$ git open --print
# prints https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
#### Without using a framework
$ git open --suffix pulls
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls
```
## Installation
### Basic install
The preferred way of installation is to simply add the `git-open` script
somewhere into your path (e.g. add the directory to your `PATH` environment
or copy `git-open` into an existing included path like `/usr/local/bin`).
You can use also `npm` to install an OLD (1 year ago) version of this package:
### Install via NPM:
npm install --global git-open
```sh
npm install --global git-open
```
#### Using a ZSH Framework
### Windows Powershell
##### [Antigen](https://github.com/zsh-users/antigen)
Save git-open anywhere, say as ~/Documents/Scripts/git-open.sh and define
a function in your Powershell profile (see ~/Documents/WindowsPowerShell/profile.ps1) like this:
```sh
function git-open { cmd /c "C:\Program Files\Git\usr\bin\bash.exe" "~/Documents/Scripts/git-open.sh" }
Set-Alias -Name gop -Value git-open
```
### Windows with `cmd` terminal
Save the `git-open` script in any place accessible via your `%PATH%` environment var.
### ZSH
#### [Antigen](https://github.com/zsh-users/antigen)
Add `antigen bundle paulirish/git-open` to your `.zshrc` with your other bundle
commands.
@ -44,25 +89,34 @@ start zsh, and periodically checking for updates to the git repository. You can
also add the plugin to a running zsh with `antigen bundle paulirish/git-open`
for testing before adding it to your `.zshrc`.
##### [Oh-My-Zsh](http://ohmyz.sh/)
#### [Oh-My-Zsh](http://ohmyz.sh/)
1. `cd ~/.oh-my-zsh/custom/plugins`
1. `git clone git@github.com:paulirish/git-open.git gitopen`
1. Add git-open to your plugin list - edit `~/.zshrc` and change
`plugins=(...)` to `plugins=(... gitopen)`
1. `git clone https://github.com/paulirish/git-open.git $ZSH_CUSTOM/plugins/git-open`
2. Add `git-open` to your plugin list - edit `~/.zshrc` and change
`plugins=(...)` to `plugins=(... git-open)`
3. `source ~/.zshrc`
##### [Zgen](https://github.com/tarjoilija/zgen)
#### [Zgen](https://github.com/tarjoilija/zgen)
Add `zgen load paulirish/git-open` to your .zshrc file in the same function
you're doing your other `zgen load` calls in. ZGen will take care of cloning
the repository the next time you run `zgen save`, and will also periodically
check for updates to the git repository.
##### [zplug](https://github.com/zplug/zplug)
#### [zplug](https://github.com/zplug/zplug)
`zplug "paulirish/git-open", as:command`
`zplug "paulirish/git-open", as:plugin`
### Supported remote repositories
### Bash
#### [Oh-My-Bash](https://github.com/ohmybash/oh-my-bash)
1. `git clone https://github.com/paulirish/git-open.git $OSH_CUSTOM/plugins/git-open`
2. Add `git-open` to your plugin list - edit `~/.bashrc` and change
`plugins=(...)` to `plugins=(... git-open)`
3. `source ~/.bashrc`
## Supported remote repositories
git-open can automatically guess the corresponding repository page for remotes
(default looks for `origin`) on the following hosts:
@ -70,39 +124,61 @@ git-open can automatically guess the corresponding repository page for remotes
- github.com
- gist.github.com
- gitlab.com
- Gitlab custom hosted (see below)
- GitLab custom hosted (see below)
- bitbucket.org
- Atlassian Bitbucket Server (formerly _Atlassian Stash_)
- Visual Studio Team Services
- Team Foundation Server (on-premises)
- AWS Code Commit
- cnb.cool
#### Gitlab support
## Configuration
To configure gitlab support globally you need to set `gitopen.gitlab.domain`
See the [man page](git-open.1.md) for more information on how to configure `git-open`.
git config --global gitopen.gitlab.domain [yourdomain.here]
or in your local repository:
git config gitopen.gitlab.domain [yourdomain.here]
## Related projects / alternatives
## Alternative projects
See [hub](https://github.com/github/hub) for complete GitHub opening support.
It's the official GitHub project and provides `hub browse`.
Homebrew has an alternate [git-open](https://github.com/jeffreyiacono/git-open)
[Homebrew has an alternate git-open](https://github.com/jeffreyiacono/git-open)
that only works with GitHub but can open user profile pages, too.
@[gerep has an alternate git-open](https://github.com/gerep/git-open) that
works with a few providers. Of note, it opens the default view for BitBucket
instead of the source view.
And, of course, [jasonmccreary's original gh](https://github.com/jasonmccreary/gh)
from which this plugin was forked.
## Thanks
[jasonmccreary](https://github.com/jasonmccreary/) did
[all the hard work](https://github.com/jasonmccreary/gh)
[jasonmccreary](https://github.com/jasonmccreary/) did [the initial hard work](https://github.com/jasonmccreary/gh). Since then, [many contributors](https://github.com/paulirish/git-open/graphs/contributors) have submitted great PRs.
See the contributors tab for a growing list of people who have submitted PRs.
## Contributing
## Contributing & Development
Please provide examples of the URLs you are parsing with each PR.
### Testing:
You'll need to install [bats](https://github.com/sstephenson/bats#installing-bats-from-source), the Bash automated testing system. It's also available as `brew install bats`
```sh
git submodule update --init # pull in the assertion libraries
# Run the test suite once:
bats test # or `npm run unit`
# Run it on every change with `entr`
brew install entr
npm run watch
```
## Related projects
- [`git recent`](https://github.com/paulirish/git-recent) - View your most recent git branches
- [`diff-so-fancy`](https://github.com/so-fancy/diff-so-fancy/) - Making the output of `git diff` so fancy
## License
Copyright Jason McCreary & Paul Irish. Licensed under MIT.
@ -110,8 +186,17 @@ Copyright Jason McCreary & Paul Irish. Licensed under MIT.
## Changelog
- **2016-07-22** - 1.1.0, update and add linters for package.json, readme.
Re-publish to NPM.
- **2016-07-11** - Changelog started (readme formatting and installation
instructions updated)
- **2018-12-03** - [2.1.0 shipped](https://github.com/paulirish/git-open/releases/tag/v2.1.0).
- **2017-12-01** - [2.0 shipped](https://github.com/paulirish/git-open/releases/tag/v2.0.0). Breaking change: [Gitlab configuration](https://github.com/paulirish/git-open#configuration) handled differently.
- **2017-12-01** - Configuration for custom remote added
- **2017-11-30** - Support for VSTS Added
- **2017-10-31** - `--issue` and `-h` added
- **2017-10-30** - Configuration for custom domains added
- **2017-10-30** - WSL support added
- **2017-06-16** - Introduced a test suite in BATS
- **2017-06-15** - Entire script rewritten and simplified by @dermagia
- **2016-07-23** - Readme: fix oh-my-zsh install instructions
- **2016-07-22** - 1.1.0 shipped. update and add linters for package.json, readme.
- **2016-07-11** - Readme formatting and installation instructions updated. Changelog started

26
changelog.md Normal file
View file

@ -0,0 +1,26 @@
## [Version 2.1.0](https://github.com/paulirish/git-open/releases/tag/v2.1.0) (2018-12-3)
[Full changelog](https://github.com/paulirish/git-open/compare/v2.0.0...v2.1.0)
### New features
- Support opening current tag / commit: [#130](https://github.com/paulirish/git-open/pull/130)
- Add man page: [#110](https://github.com/paulirish/git-open/pull/110)
- Add support for sshconfig expansion: [#109](https://github.com/paulirish/git-open/pull/109)
- Add support for Bitbucket Server with different root context: [#113](https://github.com/paulirish/git-open/pull/113)
- Add support for AWS Code commit.: [#128](https://github.com/paulirish/git-open/pull/128)
### Bug fixes
- Fix bug with open -i on default VSTS project repo: [`67b72ac`](https://github.com/paulirish/git-open/commit/67b72ac), [`aea6e3e`](https://github.com/paulirish/git-open/commit/aea6e3e)
- Use ls-remote --get-url to get remote url: [`740222b`](https://github.com/paulirish/git-open/commit/740222b)
- Fix shellcheck: [`775361b`](https://github.com/paulirish/git-open/commit/775361b)
- Fix incompatability with bash < 4: [`895240f`](https://github.com/paulirish/git-open/commit/895240f)
- Swap uppercase/lowercase for ssh feature: [`995e915`](https://github.com/paulirish/git-open/commit/995e915) ([#123](https://github.com/paulirish/git-open/issues/123))
- Remove openopt, allow spaces in $BROWSER: [`96c80ff`](https://github.com/paulirish/git-open/commit/96c80ff)
- readme: One liner install for oh-my-zsh: [`29434cd`](https://github.com/paulirish/git-open/commit/29434cd)
- deps: change markdownlint to markdownlint-cli: [`702b8a6`](https://github.com/paulirish/git-open/commit/702b8a6), [`5b815cb`](https://github.com/paulirish/git-open/commit/5b815cb)
---
Generated by [changelog.md](https://github.com/egoist/changelog.md)

387
git-open
View file

@ -1,114 +1,323 @@
#!/usr/bin/env bash
# Opens the github page for a repo/branch in your browser.
# https://github.com/paulirish/git-open/
#
# git open
# git open [remote] [branch]
# Use git-sh-setup, similar to git-rebase
# https://www.kernel.org/pub/software/scm/git/docs/git-sh-setup.html
# https://github.com/git/git/blob/master/git-rebase.sh
# shellcheck disable=SC2034
OPTIONS_STUCKLONG=t
# shellcheck disable=SC2034
OPTIONS_KEEPDASHDASH=
# shellcheck disable=SC2034
OPTIONS_SPEC="\
git open [options]
git open [remote] [branch]
--
Opens the GitHub page for a repo/branch in your browser.
https://github.com/paulirish/git-open/
Available options are
c,commit! open current commit
i,issue! open issues page
s,suffix= append this suffix
f,file= append this file
p,print! just print the url
"
# https://github.com/koalaman/shellcheck/wiki/SC1090
# shellcheck source=/dev/null
SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup"
# Defaults
is_commit=0
is_issue=0
protocol="https"
print_only=0
suffix_flag=""
file_flag=""
while test $# != 0; do
case "$1" in
--commit) is_commit=1;;
--issue) is_issue=1;;
--suffix=*) suffix_flag="$1";;
--file=*) file_flag="$1";;
--print) print_only=1;;
--) shift; break ;;
esac
shift
done
# parse suffix from suffix=value
IFS='=' read -ra suffix_flag <<< "$suffix_flag"
function join_by { local IFS="$1"; shift; echo "$*"; }
suffix=$(join_by "=" "${suffix_flag[@]:1}")
# parse file from file=value
IFS='=' read -ra file_flag <<< "$file_flag"
file=$(join_by "=" "${file_flag[@]:1}")
# are we in a git repo?
git rev-parse --is-inside-work-tree &>/dev/null
if [[ $? != 0 ]]; then
echo "Not a git repository."
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
echo "Not a git repository." 1>&2
exit 1
fi
# choose remote. priority to: provided argument, default in config, detected tracked remote, 'origin'
branch=${2:-$(git symbolic-ref -q --short HEAD)}
upstream_branch_full_name=$(git config "branch.$branch.merge")
upstream_branch=${upstream_branch_full_name#"refs/heads/"}
tracked_remote=$(git config "branch.$branch.remote")
default_remote=$(git config open.default.remote)
remote=${1:-$default_remote}
remote=${remote:-$tracked_remote}
remote=${remote:-"origin"}
# assume origin if not provided
# fallback to upstream if neither is present.
remote="origin"
if [ -n "$1" ]; then
remote="$1"
fi
giturl=$(git ls-remote --get-url "$remote")
remote_url="remote.${remote}.url"
giturl=$(git config --get "$remote_url")
if [ -z "$giturl" ]; then
echo "$remote_url not set."
if [[ -z "$giturl" ]]; then
echo "Git remote is not set for $remote" 1>&2
exit 1
fi
# get current branch
if [ -z "$2" ]; then
branch=$(git symbolic-ref -q --short HEAD)
else
branch="$2"
fi
# Make # and % characters url friendly
# github.com/paulirish/git-open/pull/24
branch=${branch//%/%25} && branch=${branch//#/%23}
# URL normalization
# Github gists
if grep -q gist.github <<<$giturl; then
giturl=${giturl/git\@gist.github\.com\:/https://gist.github.com}
providerUrlDifference=tree
# Github
elif grep -q github <<<$giturl; then
giturl=${giturl/git\@github\.com\:/https://github.com/}
# handle SSH protocol (links like ssh://git@github.com/user/repo)
giturl=${giturl/#ssh\:\/\/git\@github\.com\//https://github.com/}
providerUrlDifference=tree
# bitbucket
elif grep -q bitbucket <<<$giturl; then
giturl=${giturl/git\@bitbucket\.org\:/https://bitbucket.org/}
# handle SSH protocol (change ssh://https://bitbucket.org/user/repo to https://bitbucket.org/user/repo)
giturl=${giturl/#ssh\:\/\/git\@/https://}
rev="$(git rev-parse HEAD)"
git_pwd="$(git rev-parse --show-prefix)"
providerUrlDifference="src/${rev}/${git_pwd}"
branch="?at=${branch}"
# Atlassian Bitbucket Server
elif grep -q "/scm/" <<<$giturl; then
re='(.*)/scm/(.*)/(.*)\.git'
if [[ $giturl =~ $re ]]; then
giturl=${BASH_REMATCH[1]}/projects/${BASH_REMATCH[2]}/repos/${BASH_REMATCH[3]}
providerUrlDifference=browse
branch="?at=refs%2Fheads%2F${branch}"
fi
# Gitlab
else
# custom gitlab
gitlab_domain=$(git config --get gitopen.gitlab.domain)
if [ -n "$gitlab_domain" ]; then
if grep -q "$gitlab_domain" <<<$giturl; then
giturl=${giturl/git\@${gitlab_domain}:/https://${gitlab_domain}/}
providerUrlDifference=tree
ssh_config=${ssh_config:-"$HOME/.ssh/config"}
# Resolves an ssh alias defined in ssh_config to it's corresponding hostname
# echos out result, should be used within subshell $( ssh_resolve $host )
# echos out nothing if alias could not be resolved
function ssh_resolve() {
domain="$1"
ssh_found=true
# Filter to only ssh_config lines that start with "Host" or "HostName"
resolved=$(while read -r ssh_line; do
# Split each line by spaces, of the form:
# Host alias [alias...]
# Host regex
# HostName resolved.domain.com
read -r -a ssh_array <<<"${ssh_line}"
ssh_optcode="$(echo "${ssh_array[0]}" | tr '[:lower:]' '[:upper:]')"
if [[ $ssh_optcode == HOST ]]; then
# Host
ssh_found=false
# Iterate through aliases looking for a match
for ssh_index in $(seq 1 $((${#ssh_array[@]} - 1))); do
ssh_host=${ssh_array[$ssh_index]}
# shellcheck disable=SC2053
if [[ $domain == $ssh_host ]]; then
# Found a match, next HostName entry will be returned while matched
ssh_found=true
break
fi
done
elif $ssh_found && [[ $ssh_optcode == HOSTNAME ]]; then
# HostName, but only if ssh_found is true (the last Host entry matched)
# Replace all instances of %h with the Host alias
echo "${ssh_array[1]//%h/$domain}"
fi
done < <(grep -iE "^\\s*Host(Name)?\\s+" "$ssh_config"))
# Take only the last resolved hostname (multiple are overridden)
tail -1 <<<"$resolved"
}
# From git-fetch(5), native protocols:
# ssh://[user@]host.xz[:port]/path/to/repo.git/
# git://host.xz[:port]/path/to/repo.git/
# http[s]://host.xz[:port]/path/to/repo.git/
# ftp[s]://host.xz[:port]/path/to/repo.git/
# [user@]host.xz:path/to/repo.git/ - scp-like but is an alternative to ssh.
# [user@]hostalias:path/to/repo.git/ - handles host aliases defined in ssh_config(5)
# Determine whether this is a url (https, ssh, git+ssh...) or an scp-style path
if [[ "$giturl" =~ ^[a-z\+]+://.* ]]; then
# Trim URL scheme and possible username
gitprotocol=${giturl%%://*}
uri=${giturl#*://}
uri=${uri#*@}
# Split on first '/ to get server name and path
domain=${uri%%/*}
urlpath=${uri#*/}
# Remove port number from non-http/https protocols (ie, ssh)
if [[ $gitprotocol != 'https' && $gitprotocol != 'http' ]]; then
domain=${domain%:*}
fi
else
# Trim possible username from SSH path
uri=${giturl##*@}
# Split on first ':' to get server name and path
domain=${uri%%:*}
urlpath=${uri#*:}
# Resolve sshconfig aliases
if [[ -e "$ssh_config" ]]; then
domain_resolv=$(ssh_resolve "$domain")
if [[ -n "$domain_resolv" ]]; then
domain="$domain_resolv"
fi
# hosted gitlab
elif grep -q gitlab <<<$giturl; then
giturl=${giturl/git\@gitlab\.com\:/https://gitlab.com/}
providerUrlDifference=tree
fi
fi
giturl=${giturl%\.git}
if [ -n "$branch" ]; then
giturl="${giturl}/${providerUrlDifference}/${branch}"
# Trim "/" from beginning of URL; "/" and ".git" from end of URL
urlpath=${urlpath#/} urlpath=${urlpath%/} urlpath=${urlpath%.git}
# If the URL is provided as "http", preserve that
if [[ $gitprotocol == 'http' ]]; then
protocol='http'
fi
# simplify URL for master
giturl=${giturl/tree\/master/}
# Allow config options to replace the server or the protocol
openurl="$protocol://$domain"
function getConfig() {
config=$(git config --get-urlmatch "open.$1" "$openurl")
echo "${config:-${!1}}"
}
domain=$(getConfig "domain")
protocol=$(getConfig "protocol")
forge=$(getConfig "forge")
# Remote ref to open
remote_ref=${upstream_branch:-${branch:-$(git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)}}
# Split arguments on '/'
IFS='/' read -r -a pathargs <<<"$urlpath"
if (( is_issue )); then
# For issues, take the numbers and preprend 'issues/'
[[ $remote_ref =~ [0-9]+ ]]
providerBranchRef="/issues/${BASH_REMATCH[0]}"
else
# Make # and % characters url friendly
# github.com/paulirish/git-open/pull/24
remote_ref=${remote_ref//%/%25} remote_ref=${remote_ref//#/%23}
if [[ $forge == 'gitea' ]]; then
providerBranchRef="/src/branch/$remote_ref"
else
providerBranchRef="/tree/$remote_ref"
fi
fi
if [[ "$domain" == 'bitbucket.org' ]]; then
providerBranchRef="/src/$remote_ref"
elif [[ "${#pathargs[@]}" -ge 3 && ${pathargs[${#pathargs[@]} - 3]} == 'scm' ]]; then
# Bitbucket server always has /scm/ as the third to last segment in the url path, e.g. /scm/ppp/test-repo.git
# Anything before the 'scm' is part of the server's root context
# If there are other context parts, add them, up to (but not including) the found 'scm'
pathPref=("${pathargs[*]:0:${#pathargs[@]} - 3}")
# Replace the 'scm' element, with 'projects'. Keep the first argument, the string 'repos', and finally the rest of the arguments.
# shellcheck disable=SC2206
pathargs=(${pathPref[@]} 'projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
IFS='/' urlpath="${pathargs[*]}"
providerBranchRef="/browse?at=$remote_ref"
elif [[ "$domain" == *"bitbucket"* ]] && [[ $gitprotocol == 'ssh' ]]; then
# bitbucket repo cloned with ssh will not have /scm/ segment in url path
# e.g. /ppp/test-repo.git
# Build the repo url starting with 'projects' and then keep the first argument, the string 'repos', and finally the rest of the arguments.
# shellcheck disable=SC2206
pathargs=('projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
IFS='/' urlpath="${pathargs[*]}"
providerBranchRef="/browse?at=$remote_ref"
elif [[ "${#pathargs[@]}" -ge '2' && ${pathargs[${#pathargs[@]} - 2]} == '_git' ]]; then
# Visual Studio Team Services and Team Foundation Server always have /_git/ as the second to last segment in the url path
if (( is_issue )); then
# Switch to workitems, provide work item id if specified
urlpath="${urlpath%%/_git/*}/_workitems"
# Handle case for the default repository url
urlpath="${urlpath#_git\/*}"
providerBranchRef="?id=${remote_ref//[^0-9]/}"
else
# Keep project and repository name, append branch selector.
providerBranchRef="?version=GB$remote_ref"
fi
elif [[ "$domain" =~ amazonaws\.com$ ]]; then
# AWS Code Commit
if (( is_issue )); then
echo "Issue feature does not supported on AWS Code Commit." 1>&2
exit 1
fi
# Take region name from domain.
region=${domain#*.}
region=${region%%.*}
# Replace domain.
# Ex. git-codecommit.us-east-1.amazonaws.com -> us-east-1.console.aws.amazon.com
domain="${region}.console.aws.amazon.com"
# Replace URL path.
# Ex. v1/repos/example -> codecommit/home?region=us-east-1#/repository/example/browse/
urlpath="codecommit/home?region=${region}#/repository/${urlpath##*/}/browse/"
# Replace branch ref.
# Ex. /tree/foobar -> foobar/--/
providerBranchRef="${providerBranchRef##*/}/--/"
elif [[ "$domain" =~ cnb\.cool$ ]]; then
# cnb.cool
# Replace URL path.
# Ex. repos/example -> repos/example/-
urlpath="$urlpath/-"
if [[ $remote_ref = "master" ]]; then
# repos/example/tree/master -> repos/example/-/tree/master
urlpath="$urlpath$providerBranchRef"
fi
fi
openurl="$protocol://$domain/$urlpath"
if (( is_commit )); then
sha=$(git rev-parse HEAD)
openurl="$openurl/commit/$sha"
elif [[ $remote_ref != "master" || "$file" ]]; then
# simplify URL for master
openurl="$openurl$providerBranchRef"
fi
if [ "$file" ]; then
absfile=$(git ls-tree --full-name --name-only "$branch" "$file")
if [[ -z "$absfile" ]]; then
echo "File $file is not in repository" 1>&2
exit 1
fi
openurl="$openurl/$absfile"
fi
if [ "$suffix" ]; then
openurl="$openurl/$suffix"
fi
# get current open browser command
case $( uname -s ) in
Darwin) open=open;;
MINGW*) open=start;;
CYGWIN*) open=cygstart;;
*) open=${BROWSER:-xdg-open};;
Darwin) open='open';;
MINGW*) open='start';;
MSYS*) open='start';;
CYGWIN*) open='cygstart';;
*) # Try to detect WSL (Windows Subsystem for Linux)
if uname -r | grep -q -i Microsoft; then
open='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile Start'
else
open='xdg-open'
fi;;
esac
if (( print_only )); then
printf '%s\n' "$openurl"
exit 0
fi
# open it in a browser
$open "$giturl" &> /dev/null
exit 0
if [[ -n "$BROWSER" ]]; then
if [[ -x "$BROWSER" ]]; then
"$BROWSER" "$openurl"
exit $?
fi
if command -v -- "$BROWSER" >/dev/null 2>&1; then
"$BROWSER" "$openurl"
exit $?
fi
fi
"$open" "$openurl"

178
git-open.1.md Normal file
View file

@ -0,0 +1,178 @@
# git-open - Open the repository's website in your browser.
## SYNOPSIS
`git open` [--issue] [--commit] [--suffix some_suffix] [remote-name] [branch-name]
## DESCRIPTION
`git open` opens the repository's website in your browser. The major well known
git hosting services are supported.
## OPTIONS
`-c`, `--commit`
Open the current commit. See `EXAMPLES` for more information.
Only tested with GitHub & GitLab.
`-i`, `--issue`
Open the current issue. When the name of the current branch matches the right pattern,
it will open the webpage with that issue. See `EXAMPLES` for more information.
This only works on GitHub, GitLab, Visual Studio Team Services and Team Foundation Server at the moment.
`-s`, `--suffix` some_suffix
Append the given suffix to the url
`-p`, `--print`
Just print the URL. Do not open it in browser.
`-h`
Show a short help text.
## EXAMPLES
```sh
git open
```
It opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/
```sh
git open someremote
```
It opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/
```sh
git open someremote somebranch
```
It opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/PROVIDED_BRANCH
```sh
git open --issue
```
If branches use naming convention of `issues/#123`, it opens
https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123
```sh
git open --suffix pulls
```
It opens the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls
```sh
git open --print
```
It prints the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/
```sh
git open --commit
```
Supposing that the current sha is `2ddc8d4548d0cee3d714dcf0068dbec5b168a9b2`, it opens
https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/commit/2ddc8d4548d0cee3d714dcf0068dbec5b168a9b2
## SUPPORTED GIT HOSTING SERVICES
git-open can automatically guess the corresponding repository page for remotes
on the following git hosting services:
- github.com
- gist.github.com
- gitlab.com
- GitLab CE/EE (self hosted GitLab, see `CONFIGURATION`)
- bitbucket.org
- Atlassian Bitbucket Server (formerly _Atlassian Stash_)
- Visual Studio Team Services
- Team Foundation Server (on-premises)
## CONFIGURATION
To configure git-open you may need to set some `git config` options.
You can use `--global` to set across all repos, instead of just the current repo.
```sh
git config [--global] option value
```
### Configuring which remote to open
By default, `git open` opens the remote named `origin`. However, if your current branch is remotely-tracking a different remote, that tracked remote will be used.
In some instances, you may want to override this behavior. When you fork a project
and add a remote named `upstream` you often want that upstream to be opened
rather than your fork. To accomplish this, you can set the `open.default.remote` within your project:
```sh
git config open.default.remote upstream
```
This is equivalent to always typing `git open upstream`.
### Gitea options
To configure Gitea support you need to set the following option.
`open.[gitdomain].forge`
The git forge present at the git domain. This only needs to be set for Gitea because it uses another branch URL format.
**Example**
```sh
git config [--global] "open.https://gitea.internal.biz.forge" "gitea"
```
### GitLab options
To configure GitLab support (or other unique hosting situations) you may need to set some options.
`open.[gitdomain].domain`
The (web) domain to open based on the provided git repo domain.
`open.[gitdomain].protocol`
The (web) protocol to open based on the provided git repo domain. Defaults to `https`.
```sh
git config [--global] open.[gitdomain].domain [value]
git config [--global] open.[gitdomain].protocol [value]
```
**Example**
- Your git remote is at `ssh://git@git.internal.biz:7000/XXX/YYY.git`
- Your hosted gitlab is `http://repo.intranet/subpath/XXX/YYY`
```sh
git config [--global] "open.https://git.internal.biz.domain" "repo.intranet/subpath"
git config [--global] "open.https://git.internal.biz.protocol" "http"
```
## DEBUGGING
You can run `git-open` in `echo` mode, which doesn't open your browser, but just prints the URL to stdout:
```sh
env BROWSER='echo' ./git-open
```
## AUTHORS
Jason McCreary did the initial hard work. Paul Irish based his project on his work.
Since then many contributors have submitted great PRs.
## SEE ALSO
git(1), git-remote(1), git-config(1), [Project page](https://github.com/paulirish/git-open)

6
git-open.plugin.sh Executable file
View file

@ -0,0 +1,6 @@
# This plugin is MIT licensed to match the git-open license.
#
# Make git-open easy to install and keep up to date if you're using a
# Bash framework like oh-my-bash.
export PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )":${PATH}

9
issue_template.md Normal file
View file

@ -0,0 +1,9 @@
If an incorrect URL is opened, please provide the following so we can write a test:
#### Example clone url:
#### Example branch name:
#### Expected web URL:

View file

@ -9,6 +9,7 @@
"MD013": false,
"MD026": false,
"MD033": false,
"MD034": false,
"MD036": false,
"MD041": false
}

5324
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "git-open",
"version": "1.1.0",
"version": "3.1.0",
"description": "Type `git open` to open the GitHub/GitLab/Bitbucket homepage for a repository.",
"author": "Paul Irish (http://paulirish.com/)",
"license": "MIT",
@ -10,7 +10,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/paulirish/git-open.git"
"url": "git+https://github.com/paulirish/git-open.git"
},
"contributors": [
"Paul Irish (http://paulirish.com/)",
@ -30,14 +30,22 @@
"git-open": "git-open",
"git-home": "git-open"
},
"man": "./git-open.1",
"scripts": {
"lint:package": "echo \"\nLinting package.json\" && pjv --recommendations --warnings && echo \"OK\n\n\"",
"lint:readme": "echo \"\nLinting README.md\" && markdownlint --config markdownlint.json README.md && echo \"OK\n\n\"",
"test": "npm run --silent lint:package && npm run --silent lint:readme"
"lint:editorconfig": "eclint check ./git-open *.md *.yml",
"lint:readme": "markdownlint --config markdownlint.json README.md",
"lint:man": "markdownlint --config markdownlint.json git-open.1.md",
"man": "marked-man --version \"git-open $npm_package_version\" --manual \"Git manual\" --section 1 git-open.1.md > git-open.1",
"unit": "bats test/",
"shellcheck": "shellcheck ./git-open",
"lint": "npm run lint:readme && npm run lint:man && npm run lint:editorconfig",
"test": "npm run unit && npm run lint",
"watch": "find . -maxdepth 2 -iname '*bats' -o -iname 'git-open' | entr bats test/",
"prepublishOnly": "npm run man && npm run test"
},
"dependencies": {},
"devDependencies": {
"markdownlint": "^0.2.0",
"package-json-validator": "^0.6.1"
"eclint": "^2.1.0",
"markdownlint-cli": "^0.32.0",
"marked-man": "^0.7.0"
}
}

761
test/git-open.bats Executable file
View file

@ -0,0 +1,761 @@
#!/usr/bin/env bats
load "test_helper/bats-support/load"
load "test_helper/bats-assert/load"
foldername="sandboxrepo"
setup() {
create_git_sandbox
export BROWSER=echo
}
##
## Test environment
##
@test "test environment" {
assert_equal "$BROWSER" "echo"
cd ..
assert [ -e "$foldername" ]
assert [ -e "$foldername/.git" ]
}
##
## Help
##
@test "help text" {
run ../git-open -h
assert_output --partial "usage: git open"
}
@test "invalid option" {
run ../git-open --invalid-option
assert_output --partial "error: unknown option \`invalid-option'"
assert_output --partial "usage: git open"
}
##
## Print
##
@test "print url" {
git remote set-url origin "git@github.com:user/repo.git"
git checkout -B "master"
BROWSER="assert_failure" run ../git-open -p
assert_output "https://github.com/user/repo"
}
##
## url handling
##
@test "url: insteadOf handling" {
git config --local url.http://example.com/.insteadOf ex:
git remote set-url origin ex:example.git
git checkout -B master
run ../git-open
assert_output "http://example.com/example"
}
##
## GitHub
##
@test "gh: basic" {
git remote set-url origin "git@github.com:user/repo.git"
git checkout -B "master"
run ../git-open
assert_output "https://github.com/user/repo"
}
@test "gh: branch" {
git remote set-url origin "git@github.com:user/repo.git"
git checkout -B "mybranch"
run ../git-open
assert_output "https://github.com/user/repo/tree/mybranch"
}
@test "gh: upstream branch" {
git remote set-url origin "git@github.com:user/repo.git"
git remote add upstreamRemote "git@github.com:user/upstream-repo.git"
git checkout -B "mybranch"
git config --local "branch.mybranch.merge" "refs/heads/myupstream/mybranch"
git config --local "branch.mybranch.remote" "upstreamRemote"
run ../git-open
assert_output "https://github.com/user/upstream-repo/tree/myupstream/mybranch"
}
@test "gh: upstream branch from param" {
git remote set-url origin "git@github.com:user/repo.git"
git remote add upstreamRemote "git@github.com:user/upstream-repo.git"
git checkout -B "mybranch"
git config --local "branch.mybranch.merge" "refs/heads/upstreamBranch"
git config --local "branch.mybranch.remote" "upstreamRemote"
git checkout master
run ../git-open upstreamRemote mybranch
assert_output "https://github.com/user/upstream-repo/tree/upstreamBranch"
}
@test "gh: tag" {
git remote set-url origin "git@github.com:user/repo.git"
git tag mytag
echo a > a
git add a
git commit -m a
git checkout mytag
run ../git-open
assert_output "https://github.com/user/repo/tree/mytag"
}
@test "gh: non-origin remote" {
git remote set-url origin "git@github.com:user/repo.git"
git remote add upstream "git@github.com:upstreamorg/repo.git"
run ../git-open "upstream"
assert_output "https://github.com/upstreamorg/repo"
git checkout -B "mybranch"
run ../git-open "upstream" "otherbranch"
assert_output "https://github.com/upstreamorg/repo/tree/otherbranch"
}
@test "gh: without git user" {
# https://github.com/paulirish/git-open/pull/63
git remote set-url origin "github.com:paulirish/git-open.git"
run ../git-open
assert_output "https://github.com/paulirish/git-open"
}
@test "gh: ssh origin" {
git remote set-url origin "ssh://git@github.com/user/repo"
run ../git-open
assert_output "https://github.com/user/repo"
# https://github.com/paulirish/git-open/pull/30
git remote set-url origin "ssh://git@github.com/user/repo.git"
run ../git-open
assert_output "https://github.com/user/repo"
}
@test "gh: git protocol origin" {
git remote set-url origin "git://github.com/user/repo.git"
git checkout -B "master"
run ../git-open
assert_output "https://github.com/user/repo"
}
@test "gh: git open --issue" {
# https://github.com/paulirish/git-open/pull/46
git remote set-url origin "github.com:paulirish/git-open.git"
git checkout -B "issues/#12"
run ../git-open "--issue"
assert_output "https://github.com/paulirish/git-open/issues/12"
git checkout -B "fix-issue-37"
run ../git-open "--issue"
assert_output "https://github.com/paulirish/git-open/issues/37"
git checkout -B "fix-issue-38"
run ../git-open "-i"
assert_output "https://github.com/paulirish/git-open/issues/38"
}
@test "gh: git open --commit" {
git remote set-url origin "github.com:paulirish/git-open.git"
sha=$(git rev-parse HEAD)
run ../git-open "--commit"
assert_output "https://github.com/paulirish/git-open/commit/${sha}"
}
@test "gh: git open --suffix anySuffix" {
run ../git-open "--suffix" "anySuffix"
assert_output "https://github.com/paulirish/git-open/anySuffix"
}
@test "gh: git open --suffix anySuffix?hello=world" {
run ../git-open "--suffix" "anySuffix?hello=world"
assert_output "https://github.com/paulirish/git-open/anySuffix?hello=world"
}
@test "gh: gist" {
git remote set-url origin "git@gist.github.com:2d84a6db1b41b4020685.git"
run ../git-open
assert_output "https://gist.github.com/2d84a6db1b41b4020685"
}
@test "gh: --file option" {
run ../git-open -f readme.txt
assert_output "https://github.com/paulirish/git-open/tree/master/readme.txt"
# and now a new file in a subdirectory.
mkdir -p subdir
touch subdir/howdy.txt
git add subdir
git commit -am add-in-howdy
run ../git-open -f subdir/howdy.txt
assert_output "https://github.com/paulirish/git-open/tree/master/subdir/howdy.txt"
}
@test "basic: # and % in branch names are URL encoded" {
# https://github.com/paulirish/git-open/pull/24
git checkout -B "issue-#42"
run ../git-open
assert_output "https://github.com/paulirish/git-open/tree/issue-%2342"
git checkout -B "just-50%"
run ../git-open
assert_output "https://github.com/paulirish/git-open/tree/just-50%25"
}
@test "basic: tracked remote is default" {
# https://github.com/paulirish/git-open/issues/65
# create a local git repo I can push to
remote_name="sandboxremote"
remote_url="git@github.com:userfork/git-open.git"
# ideally we'd set a real upstream branch, but that's not possible without
# pull/push'ing over the network. So we're cheating and just setting the
# branch.<branch>.remote config
# https://github.com/paulirish/git-open/pull/88#issuecomment-339813145
git remote add $remote_name $remote_url
git config --local --add branch.master.remote $remote_name
run ../git-open
assert_output "https://github.com/userfork/git-open"
git config --local --add branch.master.remote origin
run ../git-open
assert_output "https://github.com/paulirish/git-open"
}
@test "basic: https url can contain port" {
git remote set-url origin "https://github.com:99/user/repo.git"
run ../git-open
assert_output "https://github.com:99/user/repo"
}
@test "basic: ssh url has port removed from http url" {
git remote set-url origin "ssh://github.com:22/user/repo.git"
run ../git-open
assert_output "https://github.com/user/repo"
}
@test "basic: http url scheme is preserved" {
git remote set-url origin "http://github.com/user/repo.git"
# ignore any local config like: `url.https://github.com/.insteadof=http://github.com/`
GIT_CONFIG_NOSYSTEM=1 run ../git-open
assert_output "http://github.com/user/repo"
}
@test "basic: open.default.remote configuration" {
git remote set-url origin "git@github.com:paulirish/git-open.git"
git remote add upstream "git@github.com:upstreamorg/repo.git"
git config --local open.default.remote upstream
run ../git-open
assert_output "https://github.com/upstreamorg/repo"
}
##
## SSH config
##
@test "sshconfig: basic" {
create_ssh_sandbox
# Basic
git remote set-url origin "basic:user/repo.git"
run ../git-open
assert_output --partial "https://basic.com/user/repo"
# With git user
git remote set-url origin "git@nouser:user/repo.git"
run ../git-open
assert_output "https://no.user/user/repo"
}
@test "sshconfig: no action on no match" {
create_ssh_sandbox
git remote set-url origin "git@nomatch:user/repo.git"
run ../git-open
assert_output "https://nomatch/user/repo"
# No match due to improper casing
}
@test "sshconfig: check case sensitivity" {
create_ssh_sandbox
# Host and HostName keywords should be case insensitive
# But output URL will be case sensitive
git remote set-url origin "malformed:user/repo.git"
run ../git-open
assert_output "https://MaL.FoRmEd/user/repo"
# SSH aliases (hosts) are case sensitive, this should not match
git remote set-url origin "git@MALFORMED:user/repo.git"
run ../git-open
refute_output "https://MaL.FoRmEd/user/repo"
}
@test "sshconfig: multitarget host" {
create_ssh_sandbox
for i in $(seq 1 3); do
git remote set-url origin "multi$i:user/repo.git"
run ../git-open
assert_output "https://multi.com/user/repo"
done
}
@test "sshconfig: host substitution in hostname" {
create_ssh_sandbox
for i in $(seq 1 3); do
git remote set-url origin "sub$i:user/repo.git"
run ../git-open
assert_output "https://sub$i.multi.com/user/repo"
done
}
@test "sshconfig: host wildcard * matches zero or more chars" {
create_ssh_sandbox
# Normal *
for str in "" "-prod" "-dev"; do
git remote set-url origin "zero$str:user/repo.git"
run ../git-open
assert_output "https://zero.com/user/repo"
done
# * with substitution
for str in "" "-prod" "-dev"; do
git remote set-url origin "subzero$str:user/repo.git"
run ../git-open
assert_output "https://subzero$str.zero/user/repo"
done
}
@test "sshconfig: host wildcard ? matches exactly one char" {
create_ssh_sandbox
# Normal ?
for i in $(seq 1 3); do
git remote set-url origin "one$i:user/repo.git"
run ../git-open
assert_output "https://one.com/user/repo"
done
# Refute invalid match on ?
for str in "" "-test"; do
git remote set-url origin "one:user/repo.git"
run ../git-open
refute_output "https://one$str.com/user/repo"
done
# ? with substitution
for i in $(seq 1 3); do
git remote set-url origin "subone$i:user/repo.git"
run ../git-open
assert_output "https://subone$i.one/user/repo"
done
# Refute invalid match on ? with substitution
for str in "" "-test"; do
git remote set-url origin "subone$str:user/repo.git"
run ../git-open
refute_output "https://subone$str.one/user/repo"
done
# Refute invalid match on ? with substitution
}
@test "sshconfig: overriding host rules" {
create_ssh_sandbox
git remote set-url origin "zero-override:user/repo.git"
run ../git-open
assert_output "https://override.zero.com/user/repo"
}
##
## Bitbucket
##
@test "bitbucket: basic" {
git remote set-url origin "git@bitbucket.org:paulirish/crbug-extension.git"
run ../git-open
assert_output --partial "https://bitbucket.org/paulirish/crbug-extension"
}
@test "bitbucket: tag" {
git remote set-url origin "git@bitbucket.org:paulirish/crbug-extension.git"
git tag mytag
echo a > a
git add a
git commit -m a
git checkout mytag
run ../git-open
assert_output "https://bitbucket.org/paulirish/crbug-extension/src/mytag"
}
@test "bitbucket: non-origin remote" {
# https://github.com/paulirish/git-open/pull/4
git remote add bbclone "git@bitbucket.org:rwhitbeck/git-open.git"
run ../git-open "bbclone"
assert_output "https://bitbucket.org/rwhitbeck/git-open"
}
@test "bitbucket: open source view" {
# https://github.com/paulirish/git-open/pull/26
git remote set-url origin "https://bitbucket.org/kisom/consbri.git"
git checkout -B "devel"
run ../git-open
refute_output --partial "//kisom"
assert_output "https://bitbucket.org/kisom/consbri/src/devel"
}
@test "bitbucket: open source view with a slash/branch" {
# https://github.com/paulirish/git-open/pull/26
# see https://github.com/paulirish/git-open/issues/80 for feat/branchname issues
git remote set-url origin "https://bitbucket.org/guyzmo/git-repo.git"
git checkout -B "bugfix/conftest_fix"
run ../git-open
assert_output "https://bitbucket.org/guyzmo/git-repo/src/bugfix/conftest_fix"
}
@test "bitbucket: ssh:// clone urls" {
# https://github.com/paulirish/git-open/pull/36
git remote set-url origin "ssh://git@bitbucket.org/lbesson/bin.git"
run ../git-open
assert_output "https://bitbucket.org/lbesson/bin"
}
@test "bitbucket: no username@ in final url" {
# https://github.com/paulirish/git-open/pull/69
git remote set-url origin "https://trend_rand@bitbucket.org/trend_rand/test-repo.git"
run ../git-open
refute_output --partial "@"
}
@test "bitbucket: Bitbucket Server" {
# https://github.com/paulirish/git-open/issues/77#issuecomment-309044010
git remote set-url origin "https://user@mybb.domain.com/scm/ppp/rrr.git"
run ../git-open
# any of the following are acceptable
assert_output "https://mybb.domain.com/projects/ppp/repos/rrr" ||
assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=master" ||
assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=refs%2Fheads%2Fmaster"
}
@test "bitbucket: Bitbucket Server branch" {
# https://github.com/paulirish/git-open/issues/80
git remote set-url origin "https://user@mybb.domain.com/scm/ppp/rrr.git"
git checkout -B "develop"
run ../git-open
# The following query args work with BB Server:
# at=refs%2Fheads%2Fdevelop, at=develop, at=refs/heads/develop
# However /src/develop does not (unlike bitbucket.org)
assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=develop" ||
assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" ||
assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs/heads/develop"
refute_output --partial "/src/develop"
}
@test "bitbucket: Bitbucket Server private user repos" {
# https://github.com/paulirish/git-open/pull/83#issuecomment-309968538
git remote set-url origin "https://mybb.domain.com/scm/~first.last/rrr.git"
git checkout -B "develop"
run ../git-open
assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=develop" ||
assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" ||
assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs/heads/develop"
}
@test "bitbucket: Bitbucket Server with different root context" {
# https://github.com/paulirish/git-open/pull/15
git remote set-url origin "https://user@bitbucket.example.com/git/scm/ppp/test-repo.git"
run ../git-open
assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo" ||
assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=master" ||
assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster"
}
@test "bitbucket: Bitbucket Server with different root context with multiple parts" {
# https://github.com/paulirish/git-open/pull/15
git remote set-url origin "https://user@bitbucket.example.com/really/long/root/context/scm/ppp/test-repo.git"
run ../git-open
assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo" ||
assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=master" ||
assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster"
}
@test "bitbucket: Bitbucket Server private user repos with different root context" {
# https://github.com/paulirish/git-open/pull/83#issuecomment-309968538
git remote set-url origin "https://mybb.domain.com/root/context/scm/~first.last/rrr.git"
git checkout -B "develop"
run ../git-open
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=develop" ||
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" ||
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop"
}
@test "bitbucket: Selfhosted Bitbucket Server with ssh:// clone urls" {
# https://github.com/paulirish/git-open/pull/174
git remote set-url origin "ssh://git@bitbucket.domain.com/ppp/rrr.git"
run ../git-open
assert_output "https://bitbucket.domain.com/projects/ppp/repos/rrr"
}
##
## GitLab
##
@test "gitlab: default ssh origin style" {
# https://github.com/paulirish/git-open/pull/55
git remote set-url origin "git@gitlab.example.com:user/repo"
run ../git-open
assert_output "https://gitlab.example.com/user/repo"
}
@test "gitlab: ssh://git@ origin" {
# https://github.com/paulirish/git-open/pull/51
git remote set-url origin "ssh://git@gitlab.domain.com/user/repo"
run ../git-open
assert_output "https://gitlab.domain.com/user/repo"
refute_output --partial "//user"
}
@test "gitlab: separate domains" {
# https://github.com/paulirish/git-open/pull/56
git remote set-url origin "git@git.example.com:namespace/project.git"
git config --local --add "open.https://git.example.com.domain" "gitlab.example.com"
run ../git-open
assert_output "https://gitlab.example.com/namespace/project"
}
@test "gitlab: special domain and path" {
git remote set-url origin "ssh://git@git.example.com:7000/XXX/YYY.git"
git config --local --add "open.https://git.example.com.domain" "repo.intranet/subpath"
git config --local --add "open.https://git.example.com.protocol" "http"
run ../git-open
assert_output "http://repo.intranet/subpath/XXX/YYY"
refute_output --partial "https://"
}
@test "gitlab: different port" {
# https://github.com/paulirish/git-open/pull/76
git remote set-url origin "ssh://git@git.example.com:7000/XXX/YYY.git"
run ../git-open
assert_output "https://git.example.com/XXX/YYY"
refute_output --partial ":7000"
git remote set-url origin "https://git.example.com:7000/XXX/YYY.git"
run ../git-open
assert_output "https://git.example.com:7000/XXX/YYY"
}
@test "gitlab: issue" {
git remote set-url origin "git@gitlab.example.com:user/repo"
git checkout -B "10-bump-up-to-v2.0"
run ../git-open "--issue"
assert_output "https://gitlab.example.com/user/repo/issues/10"
}
##
## Visual Studio Team Services
##
@test "vsts: https url" {
git remote set-url origin "https://gitopen.visualstudio.com/Project/_git/Repository"
run ../git-open
assert_output --partial "https://gitopen.visualstudio.com/Project/_git/Repository"
}
@test "vsts: ssh url" {
git remote add vsts_ssh "ssh://gitopen@gitopen.visualstudio.com:22/Project/_git/Repository"
run ../git-open "vsts_ssh"
assert_output "https://gitopen.visualstudio.com/Project/_git/Repository"
}
@test "vsts: on-premises tfs http url" {
git remote set-url origin "http://tfs.example.com:8080/Project/_git/Repository"
run ../git-open
assert_output --partial "http://tfs.example.com:8080/Project/_git/Repository"
}
@test "vsts: branch" {
git remote set-url origin "ssh://gitopen@gitopen.visualstudio.com:22/_git/Repository"
git checkout -B "mybranch"
run ../git-open
assert_output "https://gitopen.visualstudio.com/_git/Repository?version=GBmybranch"
}
@test "vsts: on-premises tfs branch" {
git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository"
git checkout -B "mybranch"
run ../git-open
assert_output "http://tfs.example.com:8080/Project/Folder/_git/Repository?version=GBmybranch"
}
@test "vsts: issue" {
git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository"
git checkout -B "bugfix-36"
run ../git-open "--issue"
assert_output "http://tfs.example.com:8080/Project/Folder/_workitems?id=36"
}
@test "vsts: default project repository - issue" {
git remote set-url origin "https://gitopen.visualstudio.com/_git/Project"
git checkout -B "bugfix-36"
run ../git-open "--issue"
assert_output "https://gitopen.visualstudio.com/Project/_workitems?id=36"
}
##
## AWS Code Commit
##
@test "aws: https url" {
git remote set-url origin "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo"
git checkout -B "master"
run ../git-open
assert_output "https://us-east-1.console.aws.amazon.com/codecommit/home?region=us-east-1#/repository/repo/browse/"
}
@test "aws: ssh url" {
git remote set-url origin "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo"
git checkout -B "master"
run ../git-open
assert_output "https://us-east-1.console.aws.amazon.com/codecommit/home?region=us-east-1#/repository/repo/browse/"
}
@test "aws: branch " {
git remote set-url origin "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo"
git checkout -B "mybranch"
run ../git-open
assert_output "https://us-east-1.console.aws.amazon.com/codecommit/home?region=us-east-1#/repository/repo/browse/mybranch/--/"
}
@test "aws: issue" {
git remote set-url origin "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo"
git checkout -B "issues/#12"
run ../git-open "--issue"
[ "$status" -eq 1 ]
assert_output "Issue feature does not supported on AWS Code Commit."
}
##
## cnb.cool
##
@test "cnb: https url" {
git remote set-url origin "https://cnb.cool/repos/repo"
git checkout -B "master"
run ../git-open
assert_output "https://cnb.cool/repos/repo/-/tree/master"
}
@test "cnb: branch " {
git remote set-url origin "https://cnb.cool/repos/repo"
git checkout -B "mybranch"
run ../git-open
assert_output "https://cnb.cool/repos/repo/-/tree/mybranch"
}
@test "cnb: issue" {
git remote set-url origin "https://cnb.cool/repos/repo"
git checkout -B "issues/10"
run ../git-open "--issue"
assert_output "https://cnb.cool/repos/repo/-/issues/10"
}
teardown() {
cd ..
rm -rf "$foldername"
rm -rf "$ssh_config"
refute [ -e "$ssh_config" ]
unset ssh_config
}
# helper to create a test git sandbox that won't dirty the real repo
function create_git_sandbox() {
rm -rf "$foldername"
mkdir "$foldername"
cd "$foldername"
# safety check. Don't muck with the git repo if we're not inside the sandbox.
assert_equal $(basename $PWD) "$foldername"
git init -q
assert [ -e "../$foldername/.git" ]
git config user.email "test@runner.com" && git config user.name "Test Runner"
# newer git auto-creates the origin remote
if ! git remote add origin "github.com:paulirish/git-open.git"; then
git remote set-url origin "github.com:paulirish/git-open.git"
fi
git checkout -B "master"
echo "ok" > readme.txt
git add readme.txt
git commit -m "add file" -q
}
# helper to create test SSH config file
function create_ssh_sandbox() {
export ssh_config=$(mktemp)
refute [ -z "$ssh_config" ]
# Populate ssh config with test data
echo "$ssh_testdata" >$ssh_config
assert [ -e "$ssh_config" ]
}
# Test SSH config data
ssh_testdata="
# Autogenerated test sshconfig for paulirish/git-open BATS tests
# It is safe to delete this file, a new one will be generated each test
Host basic
HostName basic.com
User git
Host nomatch
User git
Host nouser
HostName no.user
host malformed
hOsTnAmE MaL.FoRmEd
User other
# Multiple targets
Host multi1 multi2 multi3
HostName multi.com
User git
Host sub1 sub2 sub3
HostName %h.multi.com
User git
# Wildcard * matching (zero or more characters)
Host zero*
HostName zero.com
User git
Host subzero*
HostName %h.zero
User git
# Wildcard ? matching (exactly one character)
Host one?
HostName one.com
User git
Host subone?
HostName %h.one
User git
# Overrides rule zero*
Host zero-override
HostName override.zero.com
User git
"

@ -0,0 +1 @@
Subproject commit 9f88b4207da750093baabc4e3f41bf68f0dd3630

@ -0,0 +1 @@
Subproject commit 004e707638eedd62e0481e8cdc9223ad471f12ee