Skip to content

Commit 08fa2ab

Browse files
authored
Add a --commit option (#144)
Add a --commit option
2 parents 44382bf + 0564817 commit 08fa2ab

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

git-open

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ git open [remote] [branch]
1616
https://github.com/paulirish/git-open/
1717
1818
Available options are
19+
c,commit! open current commit
1920
i,issue! open issues page
2021
p,print! just print the url
2122
"
@@ -25,12 +26,14 @@ p,print! just print the url
2526
SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup"
2627

2728
# Defaults
29+
is_commit=0
2830
is_issue=0
2931
protocol="https"
3032
print_only=0
3133

3234
while test $# != 0; do
3335
case "$1" in
36+
--commit) is_commit=1;;
3437
--issue) is_issue=1;;
3538
--print) print_only=1;;
3639
--) shift; break ;;
@@ -227,8 +230,11 @@ fi
227230

228231
openurl="$protocol://$domain/$urlpath"
229232

230-
# simplify URL for master
231-
if [[ $remote_ref != "master" ]]; then
233+
if (( is_commit )); then
234+
sha=$(git rev-parse HEAD)
235+
openurl="$openurl/commit/$sha"
236+
elif [[ $remote_ref != "master" ]]; then
237+
# simplify URL for master
232238
openurl="$openurl$providerBranchRef"
233239
fi
234240

git-open.1.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## SYNOPSIS
55

6-
`git open` [--issue] [remote-name] [branch-name]
6+
`git open` [--issue] [--commit] [remote-name] [branch-name]
77

88

99
## DESCRIPTION
@@ -14,6 +14,10 @@ git hosting services are supported.
1414

1515
## OPTIONS
1616

17+
`-c`, `--commit`
18+
Open the current commit. See `EXAMPLES` for more information.
19+
Only tested with GitHub & GitLab.
20+
1721
`-i`, `--issue`
1822
Open the current issue. When the name of the current branch matches the right pattern,
1923
it will open the webpage with that issue. See `EXAMPLES` for more information.
@@ -58,6 +62,14 @@ git open --print
5862

5963
It prints the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/
6064

65+
```sh
66+
git open --commit
67+
```
68+
69+
Supposing that the current sha is `2ddc8d4548d0cee3d714dcf0068dbec5b168a9b2`, it opens
70+
https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/commit/2ddc8d4548d0cee3d714dcf0068dbec5b168a9b2
71+
72+
6173
## SUPPORTED GIT HOSTING SERVICES
6274

6375
git-open can automatically guess the corresponding repository page for remotes

test/git-open.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ setup() {
160160
assert_output "https://github.com/paulirish/git-open/issues/38"
161161
}
162162

163+
@test "gh: git open --commit" {
164+
git remote set-url origin "github.com:paulirish/git-open.git"
165+
sha=$(git rev-parse HEAD)
166+
run ../git-open "--commit"
167+
assert_output "https://github.com/paulirish/git-open/commit/${sha}"
168+
}
169+
163170
@test "gh: gist" {
164171
git remote set-url origin "[email protected]:2d84a6db1b41b4020685.git"
165172
run ../git-open

0 commit comments

Comments
 (0)