Skip to content

Commit fa49dee

Browse files
authored
default to tracked remote (#88)
1 parent f3dbce9 commit fa49dee

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ git open issue
1818

1919
```sh
2020
$ git open
21-
# opens https://github.com/REMOTE_ORIGIN_USER/CURRENT_REPO/tree/CURRENT_BRANCH
21+
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
2222

23-
$ git open upstream
24-
# opens https://github.com/REMOTE_UPSTREAM_USER/CURRENT_REPO/tree/CURRENT_BRANCH
23+
$ git open someremote
24+
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
2525

26-
$ git open upstream master
27-
# opens https://github.com/REMOTE_UPSTREAM_USER/CURRENT_REPO/tree/master
26+
$ git open someremote somebranch
27+
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/PROVIDED_BRANCH
2828

2929
$ git open issue
3030
# If branches use naming convention of issues/#123,
31-
# opens https://github.com/REMOTE_UPSTREAM_USER/CURRENT_REPO/issues/123
31+
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123
3232
```
3333

3434
## Installation

git-open

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ if [[ "$1" == 'issue' ]]; then
2525
shift
2626
fi
2727

28-
# assume remote origin if not provided
29-
remote=${1:-"origin"}
28+
# choose remote. priority to: provided argument, detected tracked remote, 'origin'
29+
branch_name=$(git name-rev --name-only HEAD 2>/dev/null)
30+
tracked_remote=$(git config "branch.$branch_name.remote")
31+
remote=${1:-$tracked_remote}
32+
remote=${remote:-"origin"}
3033

3134
# @TODO ls-remote will also expand "insteadOf" items `giturl=$(git ls-remote --get-url $remote)``
3235
giturl=$(git config --get "remote.${remote}.url")

test/git-open.bats

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ setup() {
104104
assert_output "https://github.com/paulirish/git-open/tree/just-50%25"
105105
}
106106

107+
@test "basic: tracked remote is default" {
108+
# https://github.com/paulirish/git-open/issues/65
109+
110+
# create a local git repo I can push to
111+
remote_name="sandboxremote"
112+
remote_url="[email protected]:userfork/git-open.git"
113+
114+
# ideally we'd set a real upstream branch, but that's not possible without
115+
# pull/push'ing over the network. So we're cheating and just setting the
116+
# branch.<branch>.remote config
117+
# https://github.com/paulirish/git-open/pull/88#issuecomment-339813145
118+
git remote add $remote_name $remote_url
119+
git config --local --add branch.master.remote $remote_name
120+
121+
run ../git-open
122+
assert_output "https://github.com/userfork/git-open"
123+
124+
git config --local --add branch.master.remote origin
125+
run ../git-open
126+
assert_output "https://github.com/paulirish/git-open"
127+
}
107128

108129

109130
##

0 commit comments

Comments
 (0)