File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff 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
1920i,issue! open issues page
2021p,print! just print the url
2122"
@@ -25,12 +26,14 @@ p,print! just print the url
2526SUBDIRECTORY_OK=' Yes' . " $( git --exec-path) /git-sh-setup"
2627
2728# Defaults
29+ is_commit=0
2830is_issue=0
2931protocol=" https"
3032print_only=0
3133
3234while 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 ;;
227230
228231openurl=" $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 "
233239fi
234240
Original file line number Diff line number Diff line change 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
5963It 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
6375git-open can automatically guess the corresponding repository page for remotes
Original file line number Diff line number Diff 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 " git@gist.github.com:2d84a6db1b41b4020685.git"
165172 run ../git-open
You can’t perform that action at this time.
0 commit comments