Skip to content

Add option to ignore the currently checked out branch #195

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

Open
wants to merge 4 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Please provide examples of the URLs you are parsing with each PR.

### 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`
You'll need to install [bats](https://github.com/bats-core/bats-core), the Bash automated testing system. It's also available as `brew install bats-core`

```sh
git submodule update --init # pull in the assertion libraries
Expand Down
15 changes: 9 additions & 6 deletions git-open
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ git open [remote] [branch]
https://github.com/paulirish/git-open/

Available options are
c,commit! open current commit
i,issue! open issues page
s,suffix= append this suffix
p,print! just print the url
c,commit! open current commit
i,issue! open issues page
s,suffix= append this suffix
p,print! just print the url
b,ignore-branch! just open the repo regardless of the currently checked out branch
"

# https://github.com/koalaman/shellcheck/wiki/SC1090
Expand All @@ -32,13 +33,15 @@ is_issue=0
protocol="https"
print_only=0
suffix_flag=""
ignore_branch=0

while test $# != 0; do
case "$1" in
--commit) is_commit=1;;
--issue) is_issue=1;;
--suffix=*) suffix_flag="$1";;
--print) print_only=1;;
--ignore-branch) ignore_branch=1;;
--) shift; break ;;
esac
shift
Expand Down Expand Up @@ -241,8 +244,8 @@ openurl="$protocol://$domain/$urlpath"
if (( is_commit )); then
sha=$(git rev-parse HEAD)
openurl="$openurl/commit/$sha"
elif [[ $remote_ref != "master" ]]; then
# simplify URL for master
elif [[ $remote_ref != "master" && $remote_ref != "main" && $ignore_branch != 1 ]]; then
# simplify URL for master and main
openurl="$openurl$providerBranchRef"
fi

Expand Down
10 changes: 10 additions & 0 deletions git-open.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

`-b`, `--ignore-branch`
Just open the repository regardless of the currently checked out branch

`-s`, `--suffix` some_suffix
Append the given suffix to the url

Expand Down Expand Up @@ -59,6 +62,13 @@ 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 --ignore-branch
```

It won't suffix the url with `/tree/CURRENT_BRANCH` regardless of the currently checked out branch, it opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/

```sh
git open --suffix pulls
```
Expand Down
24 changes: 24 additions & 0 deletions test/git-open.bats
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ setup() {
assert_output "http://example.com/example"
}

@test "url: simplification" {
git config --local url.http://example.com/.insteadOf ex:
git remote set-url origin ex:example.git
git checkout -B main
run ../git-open
assert_output "http://example.com/example"
}

@test "url: use default branch" {
git config --local url.http://example.com/.insteadOf ex:
git remote set-url origin ex:example.git
git checkout -B development
run ../git-open -b
assert_output "http://example.com/example"
}

@test "url: use-default with suffix" {
git config --local url.http://example.com/.insteadOf ex:
git remote set-url origin ex:example.git
git checkout -B development
run ../git-open -b -s actions
assert_output "http://example.com/example/actions"
}

##
## GitHub
##
Expand Down