Merge pull request #143 from arunvelsriram/print-option

Add option to print the url
This commit is contained in:
Dave Wikoff 2019-07-06 13:17:10 -04:00 committed by GitHub
commit 44382bf541
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 7 deletions

View file

@ -29,6 +29,9 @@ $ 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
```
## Installation
@ -130,12 +133,6 @@ 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:
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`

View file

@ -17,6 +17,7 @@ git open [remote] [branch]
Available options are
i,issue! open issues page
p,print! just print the url
"
# https://github.com/koalaman/shellcheck/wiki/SC1090
@ -26,10 +27,12 @@ SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup"
# Defaults
is_issue=0
protocol="https"
print_only=0
while test $# != 0; do
case "$1" in
--issue) is_issue=1;;
--print) print_only=1;;
--) shift; break ;;
esac
shift
@ -243,6 +246,10 @@ case $( uname -s ) in
fi;;
esac
if (( print_only )); then
BROWSER="echo"
fi
# Allow printing the url if BROWSER=echo
if [[ $BROWSER != "echo" ]]; then
exec &>/dev/null

View file

@ -19,10 +19,12 @@ git hosting services are supported.
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.
`-p`, `--print`
Just print the URL. Do not open it in browser.
`-h`
Show a short help text.
## EXAMPLES
```sh
@ -50,6 +52,11 @@ 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 --print
```
It prints the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/
## SUPPORTED GIT HOSTING SERVICES

View file

@ -35,6 +35,17 @@ 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
##