Add suffix flag

Co-authored-by: Sowmiya <sowmiyamuthuraman@gmail.com>
This commit is contained in:
Dinesh 2019-09-03 13:36:17 +05:30
parent 08fa2abd7e
commit 8b909f81dc
4 changed files with 29 additions and 1 deletions

View file

@ -32,6 +32,9 @@ $ git open --issue
$ 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

View file

@ -18,6 +18,7 @@ git open [remote] [branch]
Available options are
c,commit! open current commit
i,issue! open issues page
s,suffix= append this suffix
p,print! just print the url
"
@ -30,17 +31,23 @@ is_commit=0
is_issue=0
protocol="https"
print_only=0
suffix_flag=""
while test $# != 0; do
case "$1" in
--commit) is_commit=1;;
--issue) is_issue=1;;
--suffix=*) suffix_flag="$1";;
--print) print_only=1;;
--) shift; break ;;
esac
shift
done
# parse suffix from suffix=value
IFS='=' read -ra suffix_flag <<< "$suffix_flag"
suffix=${suffix_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
@ -238,6 +245,10 @@ elif [[ $remote_ref != "master" ]]; then
openurl="$openurl$providerBranchRef"
fi
if [ "$suffix" ]; then
openurl="$openurl/$suffix"
fi
# get current open browser command
case $( uname -s ) in
Darwin) open='open';;

View file

@ -3,7 +3,7 @@
## SYNOPSIS
`git open` [--issue] [--commit] [remote-name] [branch-name]
`git open` [--issue] [--commit] [--suffix some_suffix] [remote-name] [branch-name]
## DESCRIPTION
@ -23,6 +23,9 @@ 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.
`-s`, `--suffix` some_suffix
Append the given suffix to the url
`-p`, `--print`
Just print the URL. Do not open it in browser.
@ -56,6 +59,12 @@ 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 --suffix pulls
```
It opens the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls
```sh
git open --print
```

View file

@ -167,6 +167,11 @@ setup() {
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: gist" {
git remote set-url origin "git@gist.github.com:2d84a6db1b41b4020685.git"
run ../git-open