mirror of
https://github.com/paulirish/git-open.git
synced 2026-09-10 23:46:15 -04:00
Compare commits
9 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63c0e77aaf | ||
|
|
41ebfcebe1 | ||
|
|
f4832493a0 | ||
|
|
477b196a1d | ||
|
|
a223125abc | ||
|
|
2a66fcd7e3 | ||
|
|
ce881820db | ||
|
|
a7d09090c2 | ||
|
|
866c39dbf4 |
5
.npmignore
Normal file
5
.npmignore
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
node_modules/
|
||||
sandboxrepo
|
||||
git-open.1
|
||||
bats-assert
|
||||
bats-support
|
||||
10
README.md
10
README.md
|
|
@ -107,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
|
||||
|
|
@ -121,6 +130,7 @@ git-open can automatically guess the corresponding repository page for remotes
|
|||
- Visual Studio Team Services
|
||||
- Team Foundation Server (on-premises)
|
||||
- AWS Code Commit
|
||||
- cnb.cool
|
||||
|
||||
## Configuration
|
||||
|
||||
|
|
|
|||
38
git-open
38
git-open
|
|
@ -212,6 +212,15 @@ elif [[ "${#pathargs[@]}" -ge 3 && ${pathargs[${#pathargs[@]} - 3]} == 'scm' ]];
|
|||
pathargs=(${pathPref[@]} 'projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
|
||||
IFS='/' urlpath="${pathargs[*]}"
|
||||
providerBranchRef="/browse?at=$remote_ref"
|
||||
elif [[ "$domain" == *"bitbucket"* ]] && [[ $gitprotocol == 'ssh' ]]; then
|
||||
# bitbucket repo cloned with ssh will not have /scm/ segment in url path
|
||||
# e.g. /ppp/test-repo.git
|
||||
|
||||
# Build the repo url starting with 'projects' and then keep the first argument, the string 'repos', and finally the rest of the arguments.
|
||||
# shellcheck disable=SC2206
|
||||
pathargs=('projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
|
||||
IFS='/' urlpath="${pathargs[*]}"
|
||||
providerBranchRef="/browse?at=$remote_ref"
|
||||
elif [[ "${#pathargs[@]}" -ge '2' && ${pathargs[${#pathargs[@]} - 2]} == '_git' ]]; then
|
||||
# Visual Studio Team Services and Team Foundation Server always have /_git/ as the second to last segment in the url path
|
||||
if (( is_issue )); then
|
||||
|
|
@ -246,8 +255,16 @@ elif [[ "$domain" =~ amazonaws\.com$ ]]; then
|
|||
# Replace branch ref.
|
||||
# Ex. /tree/foobar -> foobar/--/
|
||||
providerBranchRef="${providerBranchRef##*/}/--/"
|
||||
elif [[ "$domain" =~ cnb\.cool$ ]]; then
|
||||
# cnb.cool
|
||||
# Replace URL path.
|
||||
# Ex. repos/example -> repos/example/-
|
||||
urlpath="$urlpath/-"
|
||||
if [[ $remote_ref = "master" ]]; then
|
||||
# repos/example/tree/master -> repos/example/-/tree/master
|
||||
urlpath="$urlpath$providerBranchRef"
|
||||
fi
|
||||
fi
|
||||
|
||||
openurl="$protocol://$domain/$urlpath"
|
||||
|
||||
if (( is_commit )); then
|
||||
|
|
@ -259,7 +276,7 @@ elif [[ $remote_ref != "master" || "$file" ]]; then
|
|||
fi
|
||||
|
||||
if [ "$file" ]; then
|
||||
absfile=$(git ls-tree --full-name --name-only $branch $file)
|
||||
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
|
||||
|
|
@ -286,8 +303,21 @@ case $( uname -s ) in
|
|||
esac
|
||||
|
||||
if (( print_only )); then
|
||||
BROWSER="echo"
|
||||
printf '%s\n' "$openurl"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# open it in a browser
|
||||
${BROWSER:-$open} "$openurl"
|
||||
if [[ -n "$BROWSER" ]]; then
|
||||
if [[ -x "$BROWSER" ]]; then
|
||||
"$BROWSER" "$openurl"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if command -v -- "$BROWSER" >/dev/null 2>&1; then
|
||||
"$BROWSER" "$openurl"
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
"$open" "$openurl"
|
||||
|
|
|
|||
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}
|
||||
|
|
@ -183,6 +183,19 @@ setup() {
|
|||
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"
|
||||
|
|
@ -235,6 +248,14 @@ setup() {
|
|||
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
|
||||
##
|
||||
|
|
@ -473,6 +494,13 @@ setup() {
|
|||
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
|
||||
|
|
@ -613,6 +641,30 @@ setup() {
|
|||
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 ..
|
||||
|
|
|
|||
Loading…
Reference in a new issue