mirror of
https://github.com/paulirish/git-open.git
synced 2026-09-13 00:46:21 -04:00
Compare commits
No commits in common. "master" and "v3.0.0" have entirely different histories.
|
|
@ -1,5 +0,0 @@
|
||||||
node_modules/
|
|
||||||
sandboxrepo
|
|
||||||
git-open.1
|
|
||||||
bats-assert
|
|
||||||
bats-support
|
|
||||||
13
README.md
13
README.md
|
|
@ -92,9 +92,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 +106,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 +120,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
|
||||||
|
|
||||||
|
|
|
||||||
63
git-open
63
git-open
|
|
@ -19,7 +19,6 @@ git open [remote] [branch]
|
||||||
c,commit! open current commit
|
c,commit! open current commit
|
||||||
i,issue! open issues page
|
i,issue! open issues page
|
||||||
s,suffix= append this suffix
|
s,suffix= append this suffix
|
||||||
f,file= append this file
|
|
||||||
p,print! just print the url
|
p,print! just print the url
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|
@ -33,14 +32,12 @@ is_issue=0
|
||||||
protocol="https"
|
protocol="https"
|
||||||
print_only=0
|
print_only=0
|
||||||
suffix_flag=""
|
suffix_flag=""
|
||||||
file_flag=""
|
|
||||||
|
|
||||||
while test $# != 0; do
|
while test $# != 0; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--commit) is_commit=1;;
|
--commit) is_commit=1;;
|
||||||
--issue) is_issue=1;;
|
--issue) is_issue=1;;
|
||||||
--suffix=*) suffix_flag="$1";;
|
--suffix=*) suffix_flag="$1";;
|
||||||
--file=*) file_flag="$1";;
|
|
||||||
--print) print_only=1;;
|
--print) print_only=1;;
|
||||||
--) shift; break ;;
|
--) shift; break ;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -52,10 +49,6 @@ IFS='=' read -ra suffix_flag <<< "$suffix_flag"
|
||||||
function join_by { local IFS="$1"; shift; echo "$*"; }
|
function join_by { local IFS="$1"; shift; echo "$*"; }
|
||||||
suffix=$(join_by "=" "${suffix_flag[@]:1}")
|
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
|
||||||
|
|
@ -175,7 +168,6 @@ function getConfig() {
|
||||||
|
|
||||||
domain=$(getConfig "domain")
|
domain=$(getConfig "domain")
|
||||||
protocol=$(getConfig "protocol")
|
protocol=$(getConfig "protocol")
|
||||||
forge=$(getConfig "forge")
|
|
||||||
|
|
||||||
# Remote ref to open
|
# Remote ref to open
|
||||||
remote_ref=${upstream_branch:-${branch:-$(git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)}}
|
remote_ref=${upstream_branch:-${branch:-$(git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)}}
|
||||||
|
|
@ -191,11 +183,7 @@ 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}
|
remote_ref=${remote_ref//%/%25} remote_ref=${remote_ref//#/%23}
|
||||||
if [[ $forge == 'gitea' ]]; then
|
providerBranchRef="/tree/$remote_ref"
|
||||||
providerBranchRef="/src/branch/$remote_ref"
|
|
||||||
else
|
|
||||||
providerBranchRef="/tree/$remote_ref"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$domain" == 'bitbucket.org' ]]; then
|
if [[ "$domain" == 'bitbucket.org' ]]; then
|
||||||
|
|
@ -212,15 +200,6 @@ elif [[ "${#pathargs[@]}" -ge 3 && ${pathargs[${#pathargs[@]} - 3]} == 'scm' ]];
|
||||||
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=$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
|
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
|
||||||
|
|
@ -255,35 +234,18 @@ 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
|
if (( is_commit )); then
|
||||||
sha=$(git rev-parse HEAD)
|
sha=$(git rev-parse HEAD)
|
||||||
openurl="$openurl/commit/$sha"
|
openurl="$openurl/commit/$sha"
|
||||||
elif [[ $remote_ref != "master" || "$file" ]]; then
|
elif [[ $remote_ref != "master" ]]; then
|
||||||
# simplify URL for master
|
# 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
|
if [ "$suffix" ]; then
|
||||||
openurl="$openurl/$suffix"
|
openurl="$openurl/$suffix"
|
||||||
fi
|
fi
|
||||||
|
|
@ -296,28 +258,15 @@ case $( uname -s ) in
|
||||||
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 -i Microsoft; then
|
||||||
open='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile Start'
|
open='powershell.exe -NoProfile Start'
|
||||||
else
|
else
|
||||||
open='xdg-open'
|
open='xdg-open'
|
||||||
fi;;
|
fi;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if (( print_only )); then
|
if (( print_only )); then
|
||||||
printf '%s\n' "$openurl"
|
BROWSER="echo"
|
||||||
exit 0
|
|
||||||
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"
|
|
||||||
|
|
|
||||||
|
|
@ -118,20 +118,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.
|
||||||
|
|
|
||||||
|
|
@ -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}
|
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "git-open",
|
"name": "git-open",
|
||||||
"version": "3.1.0",
|
"version": "3.0.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "git-open",
|
"name": "git-open",
|
||||||
"version": "3.1.0",
|
"version": "3.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"git-home": "git-open",
|
"git-home": "git-open",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "git-open",
|
"name": "git-open",
|
||||||
"version": "3.1.0",
|
"version": "3.0.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/)",
|
||||||
|
|
|
||||||
|
|
@ -183,19 +183,6 @@ setup() {
|
||||||
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 +230,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"
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
@ -494,13 +472,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
|
||||||
|
|
@ -641,30 +612,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 ..
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue