mirror of
https://github.com/paulirish/git-open.git
synced 2026-09-10 15:36:16 -04:00
Compare commits
86 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63c0e77aaf | ||
|
|
41ebfcebe1 | ||
|
|
f4832493a0 | ||
|
|
477b196a1d | ||
|
|
a223125abc | ||
|
|
2a66fcd7e3 | ||
|
|
ce881820db | ||
|
|
a7d09090c2 | ||
|
|
866c39dbf4 | ||
|
|
64cf066704 | ||
|
|
a437297494 | ||
|
|
dd22397400 | ||
|
|
5d1f938b47 | ||
|
|
d086ab0077 | ||
|
|
281dad270e | ||
|
|
f772364eb8 | ||
|
|
17491478e6 | ||
|
|
0b626514bb | ||
|
|
1a93477f70 | ||
|
|
f11ced9a4f | ||
|
|
0b6b0a2b40 | ||
|
|
ca0214c0d6 | ||
|
|
8ac94bf7c3 | ||
|
|
0296983a28 | ||
|
|
14fdf5c96e | ||
|
|
ca8b2348f2 | ||
|
|
c908a50824 | ||
|
|
0189caeb4b | ||
|
|
3e8c908dcd | ||
|
|
3bd3524de2 | ||
|
|
1d55c4ee50 | ||
|
|
91170cd5c8 | ||
|
|
9a35780c09 | ||
|
|
d9a0d19ce2 | ||
|
|
849298fece | ||
|
|
ad8fac9309 | ||
|
|
fcbbf918f7 | ||
|
|
8b909f81dc | ||
|
|
d52366d8c9 | ||
|
|
08fa2abd7e | ||
|
|
0564817aef | ||
|
|
44382bf541 | ||
|
|
8239d0a785 | ||
|
|
7eeee771ce | ||
|
|
3d1ad212b2 | ||
|
|
4eed00f282 | ||
|
|
556dbe91f2 | ||
|
|
5344a73106 | ||
|
|
5eba420570 | ||
|
|
f02d7e97b0 | ||
|
|
301c5a619e | ||
|
|
96c80ffe80 | ||
|
|
4ca19904a2 | ||
|
|
8c8c41bd50 | ||
|
|
5fefffede3 | ||
|
|
6bb49c28c5 | ||
|
|
c5e636f423 | ||
|
|
2ef17f07d8 | ||
|
|
c68b9c16e8 | ||
|
|
557fd40b1c | ||
|
|
995e91591f | ||
|
|
d24f64da48 | ||
|
|
895240ff03 | ||
|
|
4b1e8601a7 | ||
|
|
c3fd9a48df | ||
|
|
5b815cb619 | ||
|
|
702b8a6fc6 | ||
|
|
d049d441b3 | ||
|
|
aea6e3edb7 | ||
|
|
d9b958087d | ||
|
|
775361b509 | ||
|
|
8909a2b753 | ||
|
|
7449bfa7e1 | ||
|
|
beebcdbf37 | ||
|
|
740222babf | ||
|
|
67b72ac0f2 | ||
|
|
51caa23c63 | ||
|
|
140edbbcee | ||
|
|
119ada7f69 | ||
|
|
24dd2fc5fc | ||
|
|
ed3a6d0f4d | ||
|
|
8caa9ad1da | ||
|
|
29434cd76e | ||
|
|
ade7ae1595 | ||
|
|
170159c345 | ||
|
|
2ade70e717 |
33
.github/workflows/ci.yml
vendored
Normal file
33
.github/workflows/ci.yml
vendored
Normal 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
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
node_modules/
|
||||
sandboxrepo
|
||||
git-open.1
|
||||
|
|
|
|||
5
.npmignore
Normal file
5
.npmignore
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
node_modules/
|
||||
sandboxrepo
|
||||
git-open.1
|
||||
bats-assert
|
||||
bats-support
|
||||
21
.travis.yml
21
.travis.yml
|
|
@ -1,21 +0,0 @@
|
|||
language: node_js
|
||||
node_js: "node"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- debian-sid # Grab ShellCheck from the Debian repo
|
||||
packages:
|
||||
- shellcheck
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
before_install:
|
||||
- git clone --depth 1 https://github.com/sstephenson/bats.git
|
||||
install:
|
||||
- npm install
|
||||
script:
|
||||
- npm run lint:package
|
||||
- npm run lint:readme
|
||||
- npm run lint:editorconfig
|
||||
- shellcheck git-open
|
||||
- ./bats/bin/bats test/*.bats
|
||||
88
README.md
88
README.md
|
|
@ -2,14 +2,26 @@
|
|||
|
||||
Type `git open` to open the repo website (GitHub, GitLab, Bitbucket) in your browser.
|
||||
|
||||

|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
```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)
|
||||
|
|
@ -29,6 +41,12 @@ $ git open someremote somebranch
|
|||
$ git open --issue
|
||||
# If branches use naming convention of issues/#123,
|
||||
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123
|
||||
|
||||
$ git open --print
|
||||
# prints https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
|
||||
|
||||
$ git open --suffix pulls
|
||||
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
|
@ -73,10 +91,10 @@ for testing before adding it to your `.zshrc`.
|
|||
|
||||
#### [Oh-My-Zsh](http://ohmyz.sh/)
|
||||
|
||||
1. `cd ~/.oh-my-zsh/custom/plugins`
|
||||
1. `git clone https://github.com/paulirish/git-open.git`
|
||||
1. Add `git-open` to your plugin list - edit `~/.zshrc` and change
|
||||
`plugins=(...)` to `plugins=(... git-open)`
|
||||
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)
|
||||
|
||||
|
|
@ -89,6 +107,15 @@ check for updates to the git repository.
|
|||
|
||||
`zplug "paulirish/git-open", as:plugin`
|
||||
|
||||
### 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
|
||||
|
|
@ -102,46 +129,12 @@ git-open can automatically guess the corresponding repository page for remotes
|
|||
- Atlassian Bitbucket Server (formerly _Atlassian Stash_)
|
||||
- Visual Studio Team Services
|
||||
- Team Foundation Server (on-premises)
|
||||
- AWS Code Commit
|
||||
- cnb.cool
|
||||
|
||||
## Configuration
|
||||
|
||||
### Configuring the web destination (aka GitLab support)
|
||||
|
||||
To configure GitLab support (or other unique hosting situations) you need to set some options.
|
||||
|
||||
| option name | description |
|
||||
| ------------------------- | ---------------- |
|
||||
| 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"
|
||||
```
|
||||
|
||||
### Configuring which remote to open
|
||||
|
||||
By default, `git open` opens the remote named `origin`. However, if your current branch is [remotely-tracking](https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#_tracking_branches) 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`.
|
||||
See the [man page](git-open.1.md) for more information on how to configure `git-open`.
|
||||
|
||||
## Alternative projects
|
||||
|
||||
|
|
@ -166,12 +159,7 @@ from which this plugin was forked.
|
|||
|
||||
Please provide examples of the URLs you are parsing with each PR.
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
#### Testing:
|
||||
### 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`
|
||||
|
||||
|
|
@ -198,7 +186,9 @@ Copyright Jason McCreary & Paul Irish. Licensed under MIT.
|
|||
|
||||
## Changelog
|
||||
|
||||
- **2017-12-01** - 2.0 shipped
|
||||
|
||||
- **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
|
||||
|
|
|
|||
26
changelog.md
Normal file
26
changelog.md
Normal 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)
|
||||
206
git-open
206
git-open
|
|
@ -16,7 +16,11 @@ git open [remote] [branch]
|
|||
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
|
||||
|
|
@ -24,17 +28,34 @@ i,issue! open issues page
|
|||
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?
|
||||
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
|
||||
echo "Not a git repository." 1>&2
|
||||
|
|
@ -42,27 +63,67 @@ if ! git rev-parse --is-inside-work-tree &>/dev/null; then
|
|||
fi
|
||||
|
||||
# choose remote. priority to: provided argument, default in config, detected tracked remote, 'origin'
|
||||
branch_name=$(git name-rev --name-only HEAD 2>/dev/null)
|
||||
tracked_remote=$(git config "branch.$branch_name.remote")
|
||||
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"}
|
||||
|
||||
# @TODO ls-remote will also expand "insteadOf" items `giturl=$(git ls-remote --get-url $remote)``
|
||||
giturl=$(git config --get "remote.${remote}.url")
|
||||
giturl=$(git ls-remote --get-url "$remote")
|
||||
|
||||
if [[ -z "$giturl" ]]; then
|
||||
echo "Git remote is not set for $remote" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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
|
||||
|
|
@ -86,6 +147,14 @@ else
|
|||
# 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
|
||||
fi
|
||||
fi
|
||||
|
||||
# Trim "/" from beginning of URL; "/" and ".git" from end of URL
|
||||
|
|
@ -106,51 +175,119 @@ function getConfig() {
|
|||
|
||||
domain=$(getConfig "domain")
|
||||
protocol=$(getConfig "protocol")
|
||||
forge=$(getConfig "forge")
|
||||
|
||||
# Get current branch
|
||||
branch=${2:-$(git symbolic-ref -q --short HEAD)}
|
||||
# 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='/' pathargs=($urlpath)
|
||||
IFS='/' read -r -a pathargs <<<"$urlpath"
|
||||
|
||||
if (( is_issue )); then
|
||||
# For issues, take the numbers and preprend 'issues/'
|
||||
providerBranchRef="/issues/${branch//[^0-9]/}"
|
||||
[[ $remote_ref =~ [0-9]+ ]]
|
||||
providerBranchRef="/issues/${BASH_REMATCH[0]}"
|
||||
else
|
||||
# Make # and % characters url friendly
|
||||
# github.com/paulirish/git-open/pull/24
|
||||
branch=${branch//%/%25} branch=${branch//#/%23}
|
||||
providerBranchRef="/tree/$branch"
|
||||
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
|
||||
# Bitbucket, see https://github.com/paulirish/git-open/issues/80 for why ?at is needed.
|
||||
providerBranchRef="/src?at=$branch"
|
||||
elif [[ ${pathargs[0]} == 'scm' ]]; then
|
||||
# Bitbucket server, which starts with 'scm'
|
||||
# Replace the first element, 'scm', with 'projects'. Keep the first argument, the string 'repos', and finally the rest of the arguments.
|
||||
pathargs=('projects' ${pathargs[1]} 'repos' "${pathargs[@]:2}")
|
||||
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=$branch"
|
||||
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"
|
||||
providerBranchRef="?id=${branch//[^0-9]/}"
|
||||
# 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$branch"
|
||||
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"
|
||||
|
||||
# simplify URL for master
|
||||
if [[ $branch != "master" ]]; then
|
||||
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';;
|
||||
|
|
@ -158,20 +295,29 @@ case $( uname -s ) in
|
|||
MSYS*) open='start';;
|
||||
CYGWIN*) open='cygstart';;
|
||||
*) # Try to detect WSL (Windows Subsystem for Linux)
|
||||
if uname -r | grep -q Microsoft; then
|
||||
open='powershell.exe'
|
||||
openopt='Start'
|
||||
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
|
||||
|
||||
# Allow printing the url if BROWSER=echo
|
||||
if [[ $BROWSER != "echo" ]]; then
|
||||
exec &>/dev/null
|
||||
if (( print_only )); then
|
||||
printf '%s\n' "$openurl"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# open it in a browser
|
||||
${BROWSER:-$open} $openopt "$openurl"
|
||||
if [[ -n "$BROWSER" ]]; then
|
||||
if [[ -x "$BROWSER" ]]; then
|
||||
"$BROWSER" "$openurl"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
unset openopt
|
||||
if command -v -- "$BROWSER" >/dev/null 2>&1; then
|
||||
"$BROWSER" "$openurl"
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
"$open" "$openurl"
|
||||
|
|
|
|||
178
git-open.1.md
Normal file
178
git-open.1.md
Normal 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
6
git-open.plugin.sh
Executable 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,6 +9,7 @@
|
|||
"MD013": false,
|
||||
"MD026": false,
|
||||
"MD033": false,
|
||||
"MD034": false,
|
||||
"MD036": false,
|
||||
"MD041": false
|
||||
}
|
||||
|
|
|
|||
5324
package-lock.json
generated
Normal file
5324
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
24
package.json
24
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "git-open",
|
||||
"version": "2.0.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,18 +30,22 @@
|
|||
"git-open": "git-open",
|
||||
"git-home": "git-open"
|
||||
},
|
||||
"man": "./git-open.1",
|
||||
"scripts": {
|
||||
"lint:editorconfig": "eclint check git-open* readme* .travis.yml",
|
||||
"lint:package": "pjv --recommendations --warnings",
|
||||
"lint:readme": "node ./node_modules/markdownlint/lib/markdownlint.js --config markdownlint.json README.md",
|
||||
"test": "npm run unit && npm run lint:package && npm run lint:readme && npm run lint:editorconfig",
|
||||
"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/",
|
||||
"watch": "find . -maxdepth 2 -iname '*bats' -o -iname 'git-open' | entr 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": {
|
||||
"eclint": "^2.1.0",
|
||||
"markdownlint": "^0.2.0",
|
||||
"package-json-validator": "^0.6.1"
|
||||
"markdownlint-cli": "^0.32.0",
|
||||
"marked-man": "^0.7.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,29 @@ setup() {
|
|||
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
|
||||
##
|
||||
|
|
@ -53,6 +76,38 @@ setup() {
|
|||
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"
|
||||
|
|
@ -105,12 +160,42 @@ setup() {
|
|||
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"
|
||||
|
|
@ -158,10 +243,126 @@ setup() {
|
|||
|
||||
@test "basic: http url scheme is preserved" {
|
||||
git remote set-url origin "http://github.com/user/repo.git"
|
||||
run ../git-open
|
||||
# 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
|
||||
|
|
@ -173,6 +374,17 @@ setup() {
|
|||
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"
|
||||
|
|
@ -186,7 +398,7 @@ setup() {
|
|||
git checkout -B "devel"
|
||||
run ../git-open
|
||||
refute_output --partial "//kisom"
|
||||
assert_output "https://bitbucket.org/kisom/consbri/src?at=devel"
|
||||
assert_output "https://bitbucket.org/kisom/consbri/src/devel"
|
||||
}
|
||||
|
||||
@test "bitbucket: open source view with a slash/branch" {
|
||||
|
|
@ -195,9 +407,7 @@ setup() {
|
|||
git remote set-url origin "https://bitbucket.org/guyzmo/git-repo.git"
|
||||
git checkout -B "bugfix/conftest_fix"
|
||||
run ../git-open
|
||||
assert_output --partial "https://bitbucket.org/guyzmo/git-repo/src"
|
||||
# BB appears to be fine with both literal or URL-encoded forward slash
|
||||
assert_output --partial "?at=bugfix/conftest_fix"
|
||||
assert_output "https://bitbucket.org/guyzmo/git-repo/src/bugfix/conftest_fix"
|
||||
}
|
||||
|
||||
@test "bitbucket: ssh:// clone urls" {
|
||||
|
|
@ -214,22 +424,6 @@ setup() {
|
|||
refute_output --partial "@"
|
||||
}
|
||||
|
||||
@test "bitbucket server" {
|
||||
# https://github.com/paulirish/git-open/pull/15
|
||||
git remote set-url origin "https://user@bitbucket.example.com/scm/ppp/test-repo.git"
|
||||
run ../git-open
|
||||
assert_output "https://bitbucket.example.com/projects/ppp/repos/test-repo"
|
||||
}
|
||||
|
||||
@test "bitbucket server branch" {
|
||||
# https://github.com/paulirish/git-open/pull/15
|
||||
git remote set-url origin "https://user@bitbucket.example.com/scm/ppp/test-repo.git"
|
||||
git checkout -B "bb-server"
|
||||
run ../git-open
|
||||
assert_output "https://bitbucket.example.com/projects/ppp/repos/test-repo/browse?at=bb-server"
|
||||
}
|
||||
|
||||
|
||||
@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"
|
||||
|
|
@ -269,6 +463,45 @@ setup() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@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
|
||||
##
|
||||
|
|
@ -318,6 +551,13 @@ setup() {
|
|||
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
|
||||
##
|
||||
|
|
@ -361,10 +601,77 @@ setup() {
|
|||
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
|
||||
|
|
@ -390,3 +697,65 @@ function create_git_sandbox() {
|
|||
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
|
||||
"
|
||||
|
|
|
|||
Loading…
Reference in a new issue