Compare commits

..

No commits in common. "master" and "v2.1.0" have entirely different histories.

11 changed files with 914 additions and 4222 deletions

View file

@ -1,33 +0,0 @@
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

View file

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

23
.travis.yml Normal file
View file

@ -0,0 +1,23 @@
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
- npm run lint:man
- shellcheck git-open
- npm run man
- ./bats/bin/bats test/*.bats

View file

@ -8,20 +8,8 @@ Type `git open` to open the repo website (GitHub, GitLab, Bitbucket) in your bro
```sh ```sh
git open [remote-name] [branch-name] 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 --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) (`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)
@ -41,12 +29,6 @@ $ git open someremote somebranch
$ git open --issue $ git open --issue
# If branches use naming convention of issues/#123, # If branches use naming convention of issues/#123,
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/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 ## Installation
@ -92,9 +74,8 @@ for testing before adding it to your `.zshrc`.
#### [Oh-My-Zsh](http://ohmyz.sh/) #### [Oh-My-Zsh](http://ohmyz.sh/)
1. `git clone https://github.com/paulirish/git-open.git $ZSH_CUSTOM/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 1. Add `git-open` to your plugin list - edit `~/.zshrc` and change
`plugins=(...)` to `plugins=(... git-open)` `plugins=(...)` to `plugins=(... git-open)`
3. `source ~/.zshrc`
#### [Zgen](https://github.com/tarjoilija/zgen) #### [Zgen](https://github.com/tarjoilija/zgen)
@ -107,15 +88,6 @@ check for updates to the git repository.
`zplug "paulirish/git-open", as:plugin` `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 ## Supported remote repositories
git-open can automatically guess the corresponding repository page for remotes git-open can automatically guess the corresponding repository page for remotes
@ -130,7 +102,6 @@ git-open can automatically guess the corresponding repository page for remotes
- Visual Studio Team Services - Visual Studio Team Services
- Team Foundation Server (on-premises) - Team Foundation Server (on-premises)
- AWS Code Commit - AWS Code Commit
- cnb.cool
## Configuration ## Configuration
@ -159,6 +130,12 @@ from which this plugin was forked.
Please provide examples of the URLs you are parsing with each PR. 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` 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`
@ -186,9 +163,7 @@ Copyright Jason McCreary & Paul Irish. Licensed under MIT.
## Changelog ## Changelog
- **2017-12-01** - 2.0 shipped. Breaking change: [Gitlab configuration](https://github.com/paulirish/git-open#configuration) handled differently.
- **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-12-01** - Configuration for custom remote added
- **2017-11-30** - Support for VSTS Added - **2017-11-30** - Support for VSTS Added
- **2017-10-31** - `--issue` and `-h` added - **2017-10-31** - `--issue` and `-h` added

View file

@ -1,5 +1,5 @@
## [Version 2.1.0](https://github.com/paulirish/git-open/releases/tag/v2.1.0) (2018-12-3) ## [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) [Full changelog](https://github.com/:paulirish/git-open/compare/v2.0.0...v2.1.0)
### New features ### New features
@ -11,14 +11,14 @@
### Bug fixes ### 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) - 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) - 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 shellcheck: [`775361b`](https://github.com/:paulirish/git-open/commit/775361b)
- Fix incompatability with bash < 4: [`895240f`](https://github.com/paulirish/git-open/commit/895240f) - 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)) - 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) - 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) - 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) - deps: change markdownlint to markdownlint-cli: [`702b8a6`](https://github.com/:paulirish/git-open/commit/702b8a6), [`5b815cb`](https://github.com/:paulirish/git-open/commit/5b815cb)
--- ---

117
git-open
View file

@ -16,11 +16,7 @@ git open [remote] [branch]
https://github.com/paulirish/git-open/ https://github.com/paulirish/git-open/
Available options are Available options are
c,commit! open current commit
i,issue! open issues page 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 # https://github.com/koalaman/shellcheck/wiki/SC1090
@ -28,34 +24,17 @@ p,print! just print the url
SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup" SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup"
# Defaults # Defaults
is_commit=0
is_issue=0 is_issue=0
protocol="https" protocol="https"
print_only=0
suffix_flag=""
file_flag=""
while test $# != 0; do while test $# != 0; do
case "$1" in case "$1" in
--commit) is_commit=1;;
--issue) is_issue=1;; --issue) is_issue=1;;
--suffix=*) suffix_flag="$1";;
--file=*) file_flag="$1";;
--print) print_only=1;;
--) shift; break ;; --) shift; break ;;
esac esac
shift shift
done 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? # are we in a git repo?
if ! git rev-parse --is-inside-work-tree &>/dev/null; then if ! git rev-parse --is-inside-work-tree &>/dev/null; then
echo "Not a git repository." 1>&2 echo "Not a git repository." 1>&2
@ -63,10 +42,8 @@ if ! git rev-parse --is-inside-work-tree &>/dev/null; then
fi fi
# choose remote. priority to: provided argument, default in config, detected tracked remote, 'origin' # choose remote. priority to: provided argument, default in config, detected tracked remote, 'origin'
branch=${2:-$(git symbolic-ref -q --short HEAD)} branch_name=$(git name-rev --name-only HEAD 2>/dev/null)
upstream_branch_full_name=$(git config "branch.$branch.merge") tracked_remote=$(git config "branch.$branch_name.remote")
upstream_branch=${upstream_branch_full_name#"refs/heads/"}
tracked_remote=$(git config "branch.$branch.remote")
default_remote=$(git config open.default.remote) default_remote=$(git config open.default.remote)
remote=${1:-$default_remote} remote=${1:-$default_remote}
remote=${remote:-$tracked_remote} remote=${remote:-$tracked_remote}
@ -151,7 +128,7 @@ else
# Resolve sshconfig aliases # Resolve sshconfig aliases
if [[ -e "$ssh_config" ]]; then if [[ -e "$ssh_config" ]]; then
domain_resolv=$(ssh_resolve "$domain") domain_resolv=$(ssh_resolve "$domain")
if [[ -n "$domain_resolv" ]]; then if [[ ! -z "$domain_resolv" ]]; then
domain="$domain_resolv" domain="$domain_resolv"
fi fi
fi fi
@ -175,31 +152,26 @@ function getConfig() {
domain=$(getConfig "domain") domain=$(getConfig "domain")
protocol=$(getConfig "protocol") protocol=$(getConfig "protocol")
forge=$(getConfig "forge")
# Remote ref to open # Get current branch / tag / commit
remote_ref=${upstream_branch:-${branch:-$(git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)}} branch=${2:-$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)}
# Split arguments on '/' # Split arguments on '/'
IFS='/' read -r -a pathargs <<<"$urlpath" IFS='/' read -r -a pathargs <<<"$urlpath"
if (( is_issue )); then if (( is_issue )); then
# For issues, take the numbers and preprend 'issues/' # For issues, take the numbers and preprend 'issues/'
[[ $remote_ref =~ [0-9]+ ]] providerBranchRef="/issues/${branch//[^0-9]/}"
providerBranchRef="/issues/${BASH_REMATCH[0]}"
else else
# Make # and % characters url friendly # Make # and % characters url friendly
# github.com/paulirish/git-open/pull/24 # github.com/paulirish/git-open/pull/24
remote_ref=${remote_ref//%/%25} remote_ref=${remote_ref//#/%23} branch=${branch//%/%25} branch=${branch//#/%23}
if [[ $forge == 'gitea' ]]; then providerBranchRef="/tree/$branch"
providerBranchRef="/src/branch/$remote_ref"
else
providerBranchRef="/tree/$remote_ref"
fi
fi fi
if [[ "$domain" == 'bitbucket.org' ]]; then if [[ "$domain" == 'bitbucket.org' ]]; then
providerBranchRef="/src/$remote_ref" # Bitbucket, see https://github.com/paulirish/git-open/issues/80 for why ?at is needed.
providerBranchRef="/src?at=$branch"
elif [[ "${#pathargs[@]}" -ge 3 && ${pathargs[${#pathargs[@]} - 3]} == 'scm' ]]; then 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 # 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 # Anything before the 'scm' is part of the server's root context
@ -211,16 +183,7 @@ elif [[ "${#pathargs[@]}" -ge 3 && ${pathargs[${#pathargs[@]} - 3]} == 'scm' ]];
# shellcheck disable=SC2206 # shellcheck disable=SC2206
pathargs=(${pathPref[@]} 'projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}") pathargs=(${pathPref[@]} 'projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
IFS='/' urlpath="${pathargs[*]}" IFS='/' urlpath="${pathargs[*]}"
providerBranchRef="/browse?at=$remote_ref" providerBranchRef="/browse?at=$branch"
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 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 # 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 if (( is_issue )); then
@ -228,10 +191,10 @@ elif [[ "${#pathargs[@]}" -ge '2' && ${pathargs[${#pathargs[@]} - 2]} == '_git'
urlpath="${urlpath%%/_git/*}/_workitems" urlpath="${urlpath%%/_git/*}/_workitems"
# Handle case for the default repository url # Handle case for the default repository url
urlpath="${urlpath#_git\/*}" urlpath="${urlpath#_git\/*}"
providerBranchRef="?id=${remote_ref//[^0-9]/}" providerBranchRef="?id=${branch//[^0-9]/}"
else else
# Keep project and repository name, append branch selector. # Keep project and repository name, append branch selector.
providerBranchRef="?version=GB$remote_ref" providerBranchRef="?version=GB$branch"
fi fi
elif [[ "$domain" =~ amazonaws\.com$ ]]; then elif [[ "$domain" =~ amazonaws\.com$ ]]; then
# AWS Code Commit # AWS Code Commit
@ -255,39 +218,15 @@ elif [[ "$domain" =~ amazonaws\.com$ ]]; then
# Replace branch ref. # Replace branch ref.
# Ex. /tree/foobar -> foobar/--/ # Ex. /tree/foobar -> foobar/--/
providerBranchRef="${providerBranchRef##*/}/--/" 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 fi
openurl="$protocol://$domain/$urlpath" openurl="$protocol://$domain/$urlpath"
if (( is_commit )); then # simplify URL for master
sha=$(git rev-parse HEAD) if [[ $branch != "master" ]]; then
openurl="$openurl/commit/$sha"
elif [[ $remote_ref != "master" || "$file" ]]; then
# simplify URL for master
openurl="$openurl$providerBranchRef" openurl="$openurl$providerBranchRef"
fi 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 # get current open browser command
case $( uname -s ) in case $( uname -s ) in
Darwin) open='open';; Darwin) open='open';;
@ -295,29 +234,17 @@ case $( uname -s ) in
MSYS*) open='start';; MSYS*) open='start';;
CYGWIN*) open='cygstart';; CYGWIN*) open='cygstart';;
*) # Try to detect WSL (Windows Subsystem for Linux) *) # Try to detect WSL (Windows Subsystem for Linux)
if uname -r | grep -q -i Microsoft; then if uname -r | grep -q Microsoft; then
open='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile Start' open='powershell.exe Start'
else else
open='xdg-open' open='xdg-open'
fi;; fi;;
esac esac
if (( print_only )); then # Allow printing the url if BROWSER=echo
printf '%s\n' "$openurl" if [[ $BROWSER != "echo" ]]; then
exit 0 exec &>/dev/null
fi fi
# open it in a browser # open it in a browser
if [[ -n "$BROWSER" ]]; then ${BROWSER:-$open} "$openurl"
if [[ -x "$BROWSER" ]]; then
"$BROWSER" "$openurl"
exit $?
fi
if command -v -- "$BROWSER" >/dev/null 2>&1; then
"$BROWSER" "$openurl"
exit $?
fi
fi
"$open" "$openurl"

View file

@ -3,7 +3,7 @@
## SYNOPSIS ## SYNOPSIS
`git open` [--issue] [--commit] [--suffix some_suffix] [remote-name] [branch-name] `git open` [--issue] [remote-name] [branch-name]
## DESCRIPTION ## DESCRIPTION
@ -14,24 +14,15 @@ git hosting services are supported.
## OPTIONS ## OPTIONS
`-c`, `--commit`
Open the current commit. See `EXAMPLES` for more information.
Only tested with GitHub & GitLab.
`-i`, `--issue` `-i`, `--issue`
Open the current issue. When the name of the current branch matches the right pattern, 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. 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. 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` `-h`
Show a short help text. Show a short help text.
## EXAMPLES ## EXAMPLES
```sh ```sh
@ -59,25 +50,6 @@ git open --issue
If branches use naming convention of `issues/#123`, it opens If branches use naming convention of `issues/#123`, it opens
https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123 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 ## SUPPORTED GIT HOSTING SERVICES
@ -118,20 +90,6 @@ git config open.default.remote upstream
This is equivalent to always typing `git open 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 ### GitLab options
To configure GitLab support (or other unique hosting situations) you may need to set some options. To configure GitLab support (or other unique hosting situations) you may need to set some options.

View file

@ -1,6 +0,0 @@
# 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}

4704
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

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

View file

@ -35,17 +35,6 @@ setup() {
assert_output --partial "usage: git open" 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 ## url handling
## ##
@ -76,27 +65,6 @@ setup() {
assert_output "https://github.com/user/repo/tree/mybranch" 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" { @test "gh: tag" {
git remote set-url origin "git@github.com:user/repo.git" git remote set-url origin "git@github.com:user/repo.git"
git tag mytag git tag mytag
@ -160,42 +128,12 @@ setup() {
assert_output "https://github.com/paulirish/git-open/issues/38" 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" { @test "gh: gist" {
git remote set-url origin "git@gist.github.com:2d84a6db1b41b4020685.git" git remote set-url origin "git@gist.github.com:2d84a6db1b41b4020685.git"
run ../git-open run ../git-open
assert_output "https://gist.github.com/2d84a6db1b41b4020685" 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" { @test "basic: # and % in branch names are URL encoded" {
# https://github.com/paulirish/git-open/pull/24 # https://github.com/paulirish/git-open/pull/24
git checkout -B "issue-#42" git checkout -B "issue-#42"
@ -243,17 +181,8 @@ setup() {
@test "basic: http url scheme is preserved" { @test "basic: http url scheme is preserved" {
git remote set-url origin "http://github.com/user/repo.git" 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 run ../git-open
assert_output "https://github.com/upstreamorg/repo" assert_output "http://github.com/user/repo"
} }
## ##
@ -382,7 +311,7 @@ setup() {
git commit -m a git commit -m a
git checkout mytag git checkout mytag
run ../git-open run ../git-open
assert_output "https://bitbucket.org/paulirish/crbug-extension/src/mytag" assert_output "https://bitbucket.org/paulirish/crbug-extension/src?at=mytag"
} }
@test "bitbucket: non-origin remote" { @test "bitbucket: non-origin remote" {
@ -398,7 +327,7 @@ setup() {
git checkout -B "devel" git checkout -B "devel"
run ../git-open run ../git-open
refute_output --partial "//kisom" refute_output --partial "//kisom"
assert_output "https://bitbucket.org/kisom/consbri/src/devel" assert_output "https://bitbucket.org/kisom/consbri/src?at=devel"
} }
@test "bitbucket: open source view with a slash/branch" { @test "bitbucket: open source view with a slash/branch" {
@ -407,7 +336,9 @@ setup() {
git remote set-url origin "https://bitbucket.org/guyzmo/git-repo.git" git remote set-url origin "https://bitbucket.org/guyzmo/git-repo.git"
git checkout -B "bugfix/conftest_fix" git checkout -B "bugfix/conftest_fix"
run ../git-open run ../git-open
assert_output "https://bitbucket.org/guyzmo/git-repo/src/bugfix/conftest_fix" 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"
} }
@test "bitbucket: ssh:// clone urls" { @test "bitbucket: ssh:// clone urls" {
@ -494,13 +425,6 @@ setup() {
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" 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 ## GitLab
@ -551,13 +475,6 @@ setup() {
assert_output "https://git.example.com:7000/XXX/YYY" 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 ## Visual Studio Team Services
## ##
@ -641,30 +558,6 @@ setup() {
assert_output "Issue feature does not supported on AWS Code Commit." 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() { teardown() {
cd .. cd ..