Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[pull] master from paulirish:master #3

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
sandboxrepo
git-open.1
bats-assert
bats-support
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ git open [remote-name] [branch-name]

git open --commit
git open -c
# Open the current commit in the repo website
# 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
# If this branch is named like issue/#123, this will open the corresponding
# issue in the repo website

git open --print
git open -p
Expand Down Expand Up @@ -89,11 +89,19 @@ 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-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`

#### [Oh-My-Zsh](http://ohmyz.sh/)

1. `git clone https://github.com/paulirish/git-open.git $ZSH_CUSTOM/plugins/git-open`
1. Add `git-open` to your plugin list - edit `~/.zshrc` and change
`plugins=(...)` to `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)

Expand Down
20 changes: 10 additions & 10 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## [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)
## [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

Expand All @@ -11,14 +11,14 @@

### 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)
- 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)


---
Expand Down
35 changes: 26 additions & 9 deletions git-open
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ git open [remote] [branch]
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
"

Expand All @@ -32,12 +33,14 @@ 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
Expand All @@ -49,6 +52,10 @@ 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
Expand Down Expand Up @@ -168,6 +175,7 @@ function getConfig() {

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)}}
Expand All @@ -177,12 +185,17 @@ IFS='/' read -r -a pathargs <<<"$urlpath"

if (( is_issue )); then
# For issues, take the numbers and preprend 'issues/'
providerBranchRef="/issues/${remote_ref//[^0-9]/}"
[[ $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}
providerBranchRef="/tree/$remote_ref"
if [[ $forge == 'gitea' ]]; then
providerBranchRef="/src/branch/$remote_ref"
else
providerBranchRef="/tree/$remote_ref"
fi
fi

if [[ "$domain" == 'bitbucket.org' ]]; then
Expand Down Expand Up @@ -240,11 +253,20 @@ openurl="$protocol://$domain/$urlpath"
if (( is_commit )); then
sha=$(git rev-parse HEAD)
openurl="$openurl/commit/$sha"
elif [[ $remote_ref != "master" ]]; then
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
Expand All @@ -257,7 +279,7 @@ case $( uname -s ) in
CYGWIN*) open='cygstart';;
*) # Try to detect WSL (Windows Subsystem for Linux)
if uname -r | grep -q -i Microsoft; then
open='powershell.exe Start'
open='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile Start'
else
open='xdg-open'
fi;;
Expand All @@ -267,10 +289,5 @@ if (( print_only )); then
BROWSER="echo"
fi

# Allow printing the url if BROWSER=echo
if [[ $BROWSER != "echo" ]]; then
exec &>/dev/null
fi

# open it in a browser
${BROWSER:-$open} "$openurl"
14 changes: 14 additions & 0 deletions git-open.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ 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.
Expand Down
6 changes: 6 additions & 0 deletions git-open.plugin.sh
Original file line number Diff line number Diff line change
@@ -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}
Loading