-
Paul Irish committed 6 years ago1 parent f80f7ba2
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
-
-
1 + #!/usr/bin/env bats 2 + 3 + load "test_helper/index" 4 + 5 + ## 6 + ## Test environment 7 + ## 8 + @test "test environment" { 9 + assert_equal "$BROWSER" "echo" 10 + cd .. 11 + assert [ -e "$foldername" ] 12 + assert [ -e "$foldername/.git" ] 13 + } 14 + 15 + ## 16 + ## Help 17 + ## 18 + 19 + @test "help text" { 20 + run ../git-open -h 21 + assert_output --partial "usage: git open" 22 + } 23 + 24 + @test "invalid option" { 25 + run ../git-open --invalid-option 26 + assert_output --partial "error: unknown option \`invalid-option'" 27 + assert_output --partial "usage: git open" 28 + } 29 + 30 + ## 31 + ## url handling 32 + ## 33 + 34 + @test "url: insteadOf handling" { 35 + git config --global url.http://example.com/.insteadOf ex: 36 + git remote set-url origin ex:example.git 37 + git checkout -B master 38 + run ../git-open 39 + assert_output "http://example.com/example" 40 + } 41 + 42 + ## 43 + ## GitHub 44 + ## 45 + 46 + @test "gh: basic" { 47 + git remote set-url origin "[email protected]:user/repo.git" 48 + git checkout -B "master" 49 + run ../git-open 50 + assert_output "https://github.com/user/repo" 51 + } 52 + 53 + @test "gh: branch" { 54 + git remote set-url origin "[email protected]:user/repo.git" 55 + git checkout -B "mybranch" 56 + run ../git-open 57 + assert_output "https://github.com/user/repo/tree/mybranch" 58 + } 59 + 60 + @test "gh: non-origin remote" { 61 + git remote set-url origin "[email protected]:user/repo.git" 62 + git remote add upstream "[email protected]:upstreamorg/repo.git" 63 + run ../git-open "upstream" 64 + assert_output "https://github.com/upstreamorg/repo" 65 + 66 + git checkout -B "mybranch" 67 + run ../git-open "upstream" "otherbranch" 68 + assert_output "https://github.com/upstreamorg/repo/tree/otherbranch" 69 + } 70 + 71 + @test "gh: without git user" { 72 + # https://github.com/paulirish/git-open/pull/63 73 + git remote set-url origin "github.com:paulirish/git-open.git" 74 + run ../git-open 75 + assert_output "https://github.com/paulirish/git-open" 76 + } 77 + 78 + @test "gh: ssh origin" { 79 + git remote set-url origin "ssh://[email protected]/user/repo" 80 + run ../git-open 81 + assert_output "https://github.com/user/repo" 82 + 83 + # https://github.com/paulirish/git-open/pull/30 84 + git remote set-url origin "ssh://[email protected]/user/repo.git" 85 + run ../git-open 86 + assert_output "https://github.com/user/repo" 87 + } 88 + 89 + @test "gh: git protocol origin" { 90 + git remote set-url origin "git://github.com/user/repo.git" 91 + git checkout -B "master" 92 + run ../git-open 93 + assert_output "https://github.com/user/repo" 94 + } 95 + 96 + @test "gh: git open --issue" { 97 + # https://github.com/paulirish/git-open/pull/46 98 + git remote set-url origin "github.com:paulirish/git-open.git" 99 + git checkout -B "issues/#12" 100 + run ../git-open "--issue" 101 + assert_output "https://github.com/paulirish/git-open/issues/12" 102 + 103 + git checkout -B "fix-issue-37" 104 + run ../git-open "--issue" 105 + assert_output "https://github.com/paulirish/git-open/issues/37" 106 + 107 + git checkout -B "fix-issue-38" 108 + run ../git-open "-i" 109 + assert_output "https://github.com/paulirish/git-open/issues/38" 110 + } 111 + 112 + @test "gh: gist" { 113 + git remote set-url origin "[email protected]:2d84a6db1b41b4020685.git" 114 + run ../git-open 115 + assert_output "https://gist.github.com/2d84a6db1b41b4020685" 116 + } 117 + 118 + @test "basic: # and % in branch names are URL encoded" { 119 + # https://github.com/paulirish/git-open/pull/24 120 + git checkout -B "issue-#42" 121 + run ../git-open 122 + assert_output "https://github.com/paulirish/git-open/tree/issue-%2342" 123 + 124 + git checkout -B "just-50%" 125 + run ../git-open 126 + assert_output "https://github.com/paulirish/git-open/tree/just-50%25" 127 + } 128 + 129 + @test "basic: tracked remote is default" { 130 + # https://github.com/paulirish/git-open/issues/65 131 + 132 + # create a local git repo I can push to 133 + remote_name="sandboxremote" 134 + remote_url="[email protected]:userfork/git-open.git" 135 + 136 + # ideally we'd set a real upstream branch, but that's not possible without 137 + # pull/push'ing over the network. So we're cheating and just setting the 138 + # branch.<branch>.remote config 139 + # https://github.com/paulirish/git-open/pull/88#issuecomment-339813145 140 + git remote add $remote_name $remote_url 141 + git config --local --add branch.master.remote $remote_name 142 + 143 + run ../git-open 144 + assert_output "https://github.com/userfork/git-open" 145 + 146 + git config --local --add branch.master.remote origin 147 + run ../git-open 148 + assert_output "https://github.com/paulirish/git-open" 149 + } 150 + 151 + @test "basic: https url can contain port" { 152 + git remote set-url origin "https://github.com:99/user/repo.git" 153 + run ../git-open 154 + assert_output "https://github.com:99/user/repo" 155 + } 156 + 157 + @test "basic: ssh url has port removed from http url" { 158 + git remote set-url origin "ssh://github.com:22/user/repo.git" 159 + run ../git-open 160 + assert_output "https://github.com/user/repo" 161 + } 162 + 163 + @test "basic: http url scheme is preserved" { 164 + git remote set-url origin "http://github.com/user/repo.git" 165 + run ../git-open 166 + assert_output "http://github.com/user/repo" 167 + } 168 + 169 + 170 + ## 171 + ## Bitbucket 172 + ## 173 + 174 + @test "bitbucket: basic" { 175 + git remote set-url origin "[email protected]:paulirish/crbug-extension.git" 176 + run ../git-open 177 + assert_output --partial "https://bitbucket.org/paulirish/crbug-extension" 178 + } 179 + 180 + @test "bitbucket: non-origin remote" { 181 + # https://github.com/paulirish/git-open/pull/4 182 + git remote add bbclone "[email protected]:rwhitbeck/git-open.git" 183 + run ../git-open "bbclone" 184 + assert_output "https://bitbucket.org/rwhitbeck/git-open" 185 + } 186 + 187 + @test "bitbucket: open source view" { 188 + # https://github.com/paulirish/git-open/pull/26 189 + git remote set-url origin "https://bitbucket.org/kisom/consbri.git" 190 + git checkout -B "devel" 191 + run ../git-open 192 + refute_output --partial "//kisom" 193 + assert_output "https://bitbucket.org/kisom/consbri/src?at=devel" 194 + } 195 + 196 + @test "bitbucket: open source view with a slash/branch" { 197 + # https://github.com/paulirish/git-open/pull/26 198 + # see https://github.com/paulirish/git-open/issues/80 for feat/branchname issues 199 + git remote set-url origin "https://bitbucket.org/guyzmo/git-repo.git" 200 + git checkout -B "bugfix/conftest_fix" 201 + run ../git-open 202 + assert_output --partial "https://bitbucket.org/guyzmo/git-repo/src" 203 + # BB appears to be fine with both literal or URL-encoded forward slash 204 + assert_output --partial "?at=bugfix/conftest_fix" 205 + } 206 + 207 + @test "bitbucket: ssh:// clone urls" { 208 + # https://github.com/paulirish/git-open/pull/36 209 + git remote set-url origin "ssh://[email protected]/lbesson/bin.git" 210 + run ../git-open 211 + assert_output "https://bitbucket.org/lbesson/bin" 212 + } 213 + 214 + @test "bitbucket: no username@ in final url" { 215 + # https://github.com/paulirish/git-open/pull/69 216 + git remote set-url origin "https://[email protected]/trend_rand/test-repo.git" 217 + run ../git-open 218 + refute_output --partial "@" 219 + } 220 + 221 + @test "bitbucket: Bitbucket Server" { 222 + # https://github.com/paulirish/git-open/issues/77#issuecomment-309044010 223 + git remote set-url origin "https://[email protected]/scm/ppp/rrr.git" 224 + run ../git-open 225 + 226 + # any of the following are acceptable 227 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr" || 228 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=master" || 229 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=refs%2Fheads%2Fmaster" 230 + } 231 + 232 + @test "bitbucket: Bitbucket Server branch" { 233 + # https://github.com/paulirish/git-open/issues/80 234 + git remote set-url origin "https://[email protected]/scm/ppp/rrr.git" 235 + git checkout -B "develop" 236 + run ../git-open 237 + 238 + # The following query args work with BB Server: 239 + # at=refs%2Fheads%2Fdevelop, at=develop, at=refs/heads/develop 240 + # However /src/develop does not (unlike bitbucket.org) 241 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=develop" || 242 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 243 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs/heads/develop" 244 + 245 + refute_output --partial "/src/develop" 246 + } 247 + 248 + 249 + @test "bitbucket: Bitbucket Server private user repos" { 250 + # https://github.com/paulirish/git-open/pull/83#issuecomment-309968538 251 + git remote set-url origin "https://mybb.domain.com/scm/~first.last/rrr.git" 252 + git checkout -B "develop" 253 + run ../git-open 254 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=develop" || 255 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 256 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" 257 + 258 + } 259 + 260 + 261 + @test "bitbucket: Bitbucket Server with different root context" { 262 + # https://github.com/paulirish/git-open/pull/15 263 + git remote set-url origin "https://[email protected]/git/scm/ppp/test-repo.git" 264 + run ../git-open 265 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo" || 266 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=master" || 267 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster" 268 + } 269 + 270 + 271 + @test "bitbucket: Bitbucket Server with different root context with multiple parts" { 272 + # https://github.com/paulirish/git-open/pull/15 273 + git remote set-url origin "https://[email protected]/really/long/root/context/scm/ppp/test-repo.git" 274 + run ../git-open 275 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo" || 276 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=master" || 277 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster" 278 + } 279 + 280 + 281 + @test "bitbucket: Bitbucket Server private user repos with different root context" { 282 + # https://github.com/paulirish/git-open/pull/83#issuecomment-309968538 283 + git remote set-url origin "https://mybb.domain.com/root/context/scm/~first.last/rrr.git" 284 + git checkout -B "develop" 285 + run ../git-open 286 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=develop" || 287 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 288 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" 289 + } 290 + 291 + 292 + ## 293 + ## GitLab 294 + ## 295 + 296 + @test "gitlab: default ssh origin style" { 297 + # https://github.com/paulirish/git-open/pull/55 298 + git remote set-url origin "[email protected]:user/repo" 299 + run ../git-open 300 + assert_output "https://gitlab.example.com/user/repo" 301 + } 302 + 303 + @test "gitlab: ssh://git@ origin" { 304 + # https://github.com/paulirish/git-open/pull/51 305 + git remote set-url origin "ssh://[email protected]/user/repo" 306 + run ../git-open 307 + assert_output "https://gitlab.domain.com/user/repo" 308 + refute_output --partial "//user" 309 + } 310 + 311 + @test "gitlab: separate domains" { 312 + # https://github.com/paulirish/git-open/pull/56 313 + git remote set-url origin "[email protected]:namespace/project.git" 314 + git config --local --add "open.https://git.example.com.domain" "gitlab.example.com" 315 + run ../git-open 316 + assert_output "https://gitlab.example.com/namespace/project" 317 + } 318 + 319 + @test "gitlab: special domain and path" { 320 + git remote set-url origin "ssh://[email protected]:7000/XXX/YYY.git" 321 + git config --local --add "open.https://git.example.com.domain" "repo.intranet/subpath" 322 + git config --local --add "open.https://git.example.com.protocol" "http" 323 + 324 + run ../git-open 325 + assert_output "http://repo.intranet/subpath/XXX/YYY" 326 + refute_output --partial "https://" 327 + } 328 + 329 + @test "gitlab: different port" { 330 + # https://github.com/paulirish/git-open/pull/76 331 + git remote set-url origin "ssh://[email protected]:7000/XXX/YYY.git" 332 + run ../git-open 333 + assert_output "https://git.example.com/XXX/YYY" 334 + refute_output --partial ":7000" 335 + 336 + git remote set-url origin "https://git.example.com:7000/XXX/YYY.git" 337 + run ../git-open 338 + assert_output "https://git.example.com:7000/XXX/YYY" 339 + } 340 + 341 + ## 342 + ## Visual Studio Team Services 343 + ## 344 + 345 + @test "vsts: https url" { 346 + git remote set-url origin "https://gitopen.visualstudio.com/Project/_git/Repository" 347 + run ../git-open 348 + assert_output --partial "https://gitopen.visualstudio.com/Project/_git/Repository" 349 + } 350 + 351 + @test "vsts: ssh url" { 352 + git remote add vsts_ssh "ssh://[email protected]:22/Project/_git/Repository" 353 + run ../git-open "vsts_ssh" 354 + assert_output "https://gitopen.visualstudio.com/Project/_git/Repository" 355 + } 356 + 357 + @test "vsts: on-premises tfs http url" { 358 + git remote set-url origin "http://tfs.example.com:8080/Project/_git/Repository" 359 + run ../git-open 360 + assert_output --partial "http://tfs.example.com:8080/Project/_git/Repository" 361 + } 362 + 363 + @test "vsts: branch" { 364 + git remote set-url origin "ssh://[email protected]:22/_git/Repository" 365 + git checkout -B "mybranch" 366 + run ../git-open 367 + assert_output "https://gitopen.visualstudio.com/_git/Repository?version=GBmybranch" 368 + } 369 + 370 + @test "vsts: on-premises tfs branch" { 371 + git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository" 372 + git checkout -B "mybranch" 373 + run ../git-open 374 + assert_output "http://tfs.example.com:8080/Project/Folder/_git/Repository?version=GBmybranch" 375 + } 376 + 377 + @test "vsts: issue" { 378 + git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository" 379 + git checkout -B "bugfix-36" 380 + run ../git-open "--issue" 381 + assert_output "http://tfs.example.com:8080/Project/Folder/_workitems?id=36" 382 + } 383 + -
1 + #!/usr/bin/env bats 2 + 3 + load "test_helper/index" 4 + 5 + ## 6 + ## Test environment 7 + ## 8 + @test "test environment" { 9 + assert_equal "$BROWSER" "echo" 10 + cd .. 11 + assert [ -e "$foldername" ] 12 + assert [ -e "$foldername/.git" ] 13 + } 14 + 15 + ## 16 + ## Help 17 + ## 18 + 19 + @test "help text" { 20 + run ../git-open -h 21 + assert_output --partial "usage: git open" 22 + } 23 + 24 + @test "invalid option" { 25 + run ../git-open --invalid-option 26 + assert_output --partial "error: unknown option \`invalid-option'" 27 + assert_output --partial "usage: git open" 28 + } 29 + 30 + ## 31 + ## url handling 32 + ## 33 + 34 + @test "url: insteadOf handling" { 35 + git config --global url.http://example.com/.insteadOf ex: 36 + git remote set-url origin ex:example.git 37 + git checkout -B master 38 + run ../git-open 39 + assert_output "http://example.com/example" 40 + } 41 + 42 + ## 43 + ## GitHub 44 + ## 45 + 46 + @test "gh: basic" { 47 + git remote set-url origin "[email protected]:user/repo.git" 48 + git checkout -B "master" 49 + run ../git-open 50 + assert_output "https://github.com/user/repo" 51 + } 52 + 53 + @test "gh: branch" { 54 + git remote set-url origin "[email protected]:user/repo.git" 55 + git checkout -B "mybranch" 56 + run ../git-open 57 + assert_output "https://github.com/user/repo/tree/mybranch" 58 + } 59 + 60 + @test "gh: non-origin remote" { 61 + git remote set-url origin "[email protected]:user/repo.git" 62 + git remote add upstream "[email protected]:upstreamorg/repo.git" 63 + run ../git-open "upstream" 64 + assert_output "https://github.com/upstreamorg/repo" 65 + 66 + git checkout -B "mybranch" 67 + run ../git-open "upstream" "otherbranch" 68 + assert_output "https://github.com/upstreamorg/repo/tree/otherbranch" 69 + } 70 + 71 + @test "gh: without git user" { 72 + # https://github.com/paulirish/git-open/pull/63 73 + git remote set-url origin "github.com:paulirish/git-open.git" 74 + run ../git-open 75 + assert_output "https://github.com/paulirish/git-open" 76 + } 77 + 78 + @test "gh: ssh origin" { 79 + git remote set-url origin "ssh://[email protected]/user/repo" 80 + run ../git-open 81 + assert_output "https://github.com/user/repo" 82 + 83 + # https://github.com/paulirish/git-open/pull/30 84 + git remote set-url origin "ssh://[email protected]/user/repo.git" 85 + run ../git-open 86 + assert_output "https://github.com/user/repo" 87 + } 88 + 89 + @test "gh: git protocol origin" { 90 + git remote set-url origin "git://github.com/user/repo.git" 91 + git checkout -B "master" 92 + run ../git-open 93 + assert_output "https://github.com/user/repo" 94 + } 95 + 96 + @test "gh: git open --issue" { 97 + # https://github.com/paulirish/git-open/pull/46 98 + git remote set-url origin "github.com:paulirish/git-open.git" 99 + git checkout -B "issues/#12" 100 + run ../git-open "--issue" 101 + assert_output "https://github.com/paulirish/git-open/issues/12" 102 + 103 + git checkout -B "fix-issue-37" 104 + run ../git-open "--issue" 105 + assert_output "https://github.com/paulirish/git-open/issues/37" 106 + 107 + git checkout -B "fix-issue-38" 108 + run ../git-open "-i" 109 + assert_output "https://github.com/paulirish/git-open/issues/38" 110 + } 111 + 112 + @test "gh: gist" { 113 + git remote set-url origin "[email protected]:2d84a6db1b41b4020685.git" 114 + run ../git-open 115 + assert_output "https://gist.github.com/2d84a6db1b41b4020685" 116 + } 117 + 118 + @test "basic: # and % in branch names are URL encoded" { 119 + # https://github.com/paulirish/git-open/pull/24 120 + git checkout -B "issue-#42" 121 + run ../git-open 122 + assert_output "https://github.com/paulirish/git-open/tree/issue-%2342" 123 + 124 + git checkout -B "just-50%" 125 + run ../git-open 126 + assert_output "https://github.com/paulirish/git-open/tree/just-50%25" 127 + } 128 + 129 + @test "basic: tracked remote is default" { 130 + # https://github.com/paulirish/git-open/issues/65 131 + 132 + # create a local git repo I can push to 133 + remote_name="sandboxremote" 134 + remote_url="[email protected]:userfork/git-open.git" 135 + 136 + # ideally we'd set a real upstream branch, but that's not possible without 137 + # pull/push'ing over the network. So we're cheating and just setting the 138 + # branch.<branch>.remote config 139 + # https://github.com/paulirish/git-open/pull/88#issuecomment-339813145 140 + git remote add $remote_name $remote_url 141 + git config --local --add branch.master.remote $remote_name 142 + 143 + run ../git-open 144 + assert_output "https://github.com/userfork/git-open" 145 + 146 + git config --local --add branch.master.remote origin 147 + run ../git-open 148 + assert_output "https://github.com/paulirish/git-open" 149 + } 150 + 151 + @test "basic: https url can contain port" { 152 + git remote set-url origin "https://github.com:99/user/repo.git" 153 + run ../git-open 154 + assert_output "https://github.com:99/user/repo" 155 + } 156 + 157 + @test "basic: ssh url has port removed from http url" { 158 + git remote set-url origin "ssh://github.com:22/user/repo.git" 159 + run ../git-open 160 + assert_output "https://github.com/user/repo" 161 + } 162 + 163 + @test "basic: http url scheme is preserved" { 164 + git remote set-url origin "http://github.com/user/repo.git" 165 + run ../git-open 166 + assert_output "http://github.com/user/repo" 167 + } 168 + 169 + 170 + ## 171 + ## Bitbucket 172 + ## 173 + 174 + @test "bitbucket: basic" { 175 + git remote set-url origin "[email protected]:paulirish/crbug-extension.git" 176 + run ../git-open 177 + assert_output --partial "https://bitbucket.org/paulirish/crbug-extension" 178 + } 179 + 180 + @test "bitbucket: non-origin remote" { 181 + # https://github.com/paulirish/git-open/pull/4 182 + git remote add bbclone "[email protected]:rwhitbeck/git-open.git" 183 + run ../git-open "bbclone" 184 + assert_output "https://bitbucket.org/rwhitbeck/git-open" 185 + } 186 + 187 + @test "bitbucket: open source view" { 188 + # https://github.com/paulirish/git-open/pull/26 189 + git remote set-url origin "https://bitbucket.org/kisom/consbri.git" 190 + git checkout -B "devel" 191 + run ../git-open 192 + refute_output --partial "//kisom" 193 + assert_output "https://bitbucket.org/kisom/consbri/src?at=devel" 194 + } 195 + 196 + @test "bitbucket: open source view with a slash/branch" { 197 + # https://github.com/paulirish/git-open/pull/26 198 + # see https://github.com/paulirish/git-open/issues/80 for feat/branchname issues 199 + git remote set-url origin "https://bitbucket.org/guyzmo/git-repo.git" 200 + git checkout -B "bugfix/conftest_fix" 201 + run ../git-open 202 + assert_output --partial "https://bitbucket.org/guyzmo/git-repo/src" 203 + # BB appears to be fine with both literal or URL-encoded forward slash 204 + assert_output --partial "?at=bugfix/conftest_fix" 205 + } 206 + 207 + @test "bitbucket: ssh:// clone urls" { 208 + # https://github.com/paulirish/git-open/pull/36 209 + git remote set-url origin "ssh://[email protected]/lbesson/bin.git" 210 + run ../git-open 211 + assert_output "https://bitbucket.org/lbesson/bin" 212 + } 213 + 214 + @test "bitbucket: no username@ in final url" { 215 + # https://github.com/paulirish/git-open/pull/69 216 + git remote set-url origin "https://[email protected]/trend_rand/test-repo.git" 217 + run ../git-open 218 + refute_output --partial "@" 219 + } 220 + 221 + @test "bitbucket: Bitbucket Server" { 222 + # https://github.com/paulirish/git-open/issues/77#issuecomment-309044010 223 + git remote set-url origin "https://[email protected]/scm/ppp/rrr.git" 224 + run ../git-open 225 + 226 + # any of the following are acceptable 227 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr" || 228 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=master" || 229 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=refs%2Fheads%2Fmaster" 230 + } 231 + 232 + @test "bitbucket: Bitbucket Server branch" { 233 + # https://github.com/paulirish/git-open/issues/80 234 + git remote set-url origin "https://[email protected]/scm/ppp/rrr.git" 235 + git checkout -B "develop" 236 + run ../git-open 237 + 238 + # The following query args work with BB Server: 239 + # at=refs%2Fheads%2Fdevelop, at=develop, at=refs/heads/develop 240 + # However /src/develop does not (unlike bitbucket.org) 241 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=develop" || 242 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 243 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs/heads/develop" 244 + 245 + refute_output --partial "/src/develop" 246 + } 247 + 248 + 249 + @test "bitbucket: Bitbucket Server private user repos" { 250 + # https://github.com/paulirish/git-open/pull/83#issuecomment-309968538 251 + git remote set-url origin "https://mybb.domain.com/scm/~first.last/rrr.git" 252 + git checkout -B "develop" 253 + run ../git-open 254 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=develop" || 255 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 256 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" 257 + 258 + } 259 + 260 + 261 + @test "bitbucket: Bitbucket Server with different root context" { 262 + # https://github.com/paulirish/git-open/pull/15 263 + git remote set-url origin "https://[email protected]/git/scm/ppp/test-repo.git" 264 + run ../git-open 265 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo" || 266 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=master" || 267 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster" 268 + } 269 + 270 + 271 + @test "bitbucket: Bitbucket Server with different root context with multiple parts" { 272 + # https://github.com/paulirish/git-open/pull/15 273 + git remote set-url origin "https://[email protected]/really/long/root/context/scm/ppp/test-repo.git" 274 + run ../git-open 275 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo" || 276 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=master" || 277 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster" 278 + } 279 + 280 + 281 + @test "bitbucket: Bitbucket Server private user repos with different root context" { 282 + # https://github.com/paulirish/git-open/pull/83#issuecomment-309968538 283 + git remote set-url origin "https://mybb.domain.com/root/context/scm/~first.last/rrr.git" 284 + git checkout -B "develop" 285 + run ../git-open 286 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=develop" || 287 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 288 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" 289 + } 290 + 291 + 292 + ## 293 + ## GitLab 294 + ## 295 + 296 + @test "gitlab: default ssh origin style" { 297 + # https://github.com/paulirish/git-open/pull/55 298 + git remote set-url origin "[email protected]:user/repo" 299 + run ../git-open 300 + assert_output "https://gitlab.example.com/user/repo" 301 + } 302 + 303 + @test "gitlab: ssh://git@ origin" { 304 + # https://github.com/paulirish/git-open/pull/51 305 + git remote set-url origin "ssh://[email protected]/user/repo" 306 + run ../git-open 307 + assert_output "https://gitlab.domain.com/user/repo" 308 + refute_output --partial "//user" 309 + } 310 + 311 + @test "gitlab: separate domains" { 312 + # https://github.com/paulirish/git-open/pull/56 313 + git remote set-url origin "[email protected]:namespace/project.git" 314 + git config --local --add "open.https://git.example.com.domain" "gitlab.example.com" 315 + run ../git-open 316 + assert_output "https://gitlab.example.com/namespace/project" 317 + } 318 + 319 + @test "gitlab: special domain and path" { 320 + git remote set-url origin "ssh://[email protected]:7000/XXX/YYY.git" 321 + git config --local --add "open.https://git.example.com.domain" "repo.intranet/subpath" 322 + git config --local --add "open.https://git.example.com.protocol" "http" 323 + 324 + run ../git-open 325 + assert_output "http://repo.intranet/subpath/XXX/YYY" 326 + refute_output --partial "https://" 327 + } 328 + 329 + @test "gitlab: different port" { 330 + # https://github.com/paulirish/git-open/pull/76 331 + git remote set-url origin "ssh://[email protected]:7000/XXX/YYY.git" 332 + run ../git-open 333 + assert_output "https://git.example.com/XXX/YYY" 334 + refute_output --partial ":7000" 335 + 336 + git remote set-url origin "https://git.example.com:7000/XXX/YYY.git" 337 + run ../git-open 338 + assert_output "https://git.example.com:7000/XXX/YYY" 339 + } 340 + 341 + ## 342 + ## Visual Studio Team Services 343 + ## 344 + 345 + @test "vsts: https url" { 346 + git remote set-url origin "https://gitopen.visualstudio.com/Project/_git/Repository" 347 + run ../git-open 348 + assert_output --partial "https://gitopen.visualstudio.com/Project/_git/Repository" 349 + } 350 + 351 + @test "vsts: ssh url" { 352 + git remote add vsts_ssh "ssh://[email protected]:22/Project/_git/Repository" 353 + run ../git-open "vsts_ssh" 354 + assert_output "https://gitopen.visualstudio.com/Project/_git/Repository" 355 + } 356 + 357 + @test "vsts: on-premises tfs http url" { 358 + git remote set-url origin "http://tfs.example.com:8080/Project/_git/Repository" 359 + run ../git-open 360 + assert_output --partial "http://tfs.example.com:8080/Project/_git/Repository" 361 + } 362 + 363 + @test "vsts: branch" { 364 + git remote set-url origin "ssh://[email protected]:22/_git/Repository" 365 + git checkout -B "mybranch" 366 + run ../git-open 367 + assert_output "https://gitopen.visualstudio.com/_git/Repository?version=GBmybranch" 368 + } 369 + 370 + @test "vsts: on-premises tfs branch" { 371 + git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository" 372 + git checkout -B "mybranch" 373 + run ../git-open 374 + assert_output "http://tfs.example.com:8080/Project/Folder/_git/Repository?version=GBmybranch" 375 + } 376 + 377 + @test "vsts: issue" { 378 + git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository" 379 + git checkout -B "bugfix-36" 380 + run ../git-open "--issue" 381 + assert_output "http://tfs.example.com:8080/Project/Folder/_workitems?id=36" 382 + } 383 + -
1 + #!/usr/bin/env bats 2 + 3 + load "test_helper/index" 4 + 5 + ## 6 + ## Test environment 7 + ## 8 + @test "test environment" { 9 + assert_equal "$BROWSER" "echo" 10 + cd .. 11 + assert [ -e "$foldername" ] 12 + assert [ -e "$foldername/.git" ] 13 + } 14 + 15 + ## 16 + ## Help 17 + ## 18 + 19 + @test "help text" { 20 + run ../git-open -h 21 + assert_output --partial "usage: git open" 22 + } 23 + 24 + @test "invalid option" { 25 + run ../git-open --invalid-option 26 + assert_output --partial "error: unknown option \`invalid-option'" 27 + assert_output --partial "usage: git open" 28 + } 29 + 30 + ## 31 + ## url handling 32 + ## 33 + 34 + @test "url: insteadOf handling" { 35 + git config --global url.http://example.com/.insteadOf ex: 36 + git remote set-url origin ex:example.git 37 + git checkout -B master 38 + run ../git-open 39 + assert_output "http://example.com/example" 40 + } 41 + 42 + ## 43 + ## GitHub 44 + ## 45 + 46 + @test "gh: basic" { 47 + git remote set-url origin "[email protected]:user/repo.git" 48 + git checkout -B "master" 49 + run ../git-open 50 + assert_output "https://github.com/user/repo" 51 + } 52 + 53 + @test "gh: branch" { 54 + git remote set-url origin "[email protected]:user/repo.git" 55 + git checkout -B "mybranch" 56 + run ../git-open 57 + assert_output "https://github.com/user/repo/tree/mybranch" 58 + } 59 + 60 + @test "gh: non-origin remote" { 61 + git remote set-url origin "[email protected]:user/repo.git" 62 + git remote add upstream "[email protected]:upstreamorg/repo.git" 63 + run ../git-open "upstream" 64 + assert_output "https://github.com/upstreamorg/repo" 65 + 66 + git checkout -B "mybranch" 67 + run ../git-open "upstream" "otherbranch" 68 + assert_output "https://github.com/upstreamorg/repo/tree/otherbranch" 69 + } 70 + 71 + @test "gh: without git user" { 72 + # https://github.com/paulirish/git-open/pull/63 73 + git remote set-url origin "github.com:paulirish/git-open.git" 74 + run ../git-open 75 + assert_output "https://github.com/paulirish/git-open" 76 + } 77 + 78 + @test "gh: ssh origin" { 79 + git remote set-url origin "ssh://[email protected]/user/repo" 80 + run ../git-open 81 + assert_output "https://github.com/user/repo" 82 + 83 + # https://github.com/paulirish/git-open/pull/30 84 + git remote set-url origin "ssh://[email protected]/user/repo.git" 85 + run ../git-open 86 + assert_output "https://github.com/user/repo" 87 + } 88 + 89 + @test "gh: git protocol origin" { 90 + git remote set-url origin "git://github.com/user/repo.git" 91 + git checkout -B "master" 92 + run ../git-open 93 + assert_output "https://github.com/user/repo" 94 + } 95 + 96 + @test "gh: git open --issue" { 97 + # https://github.com/paulirish/git-open/pull/46 98 + git remote set-url origin "github.com:paulirish/git-open.git" 99 + git checkout -B "issues/#12" 100 + run ../git-open "--issue" 101 + assert_output "https://github.com/paulirish/git-open/issues/12" 102 + 103 + git checkout -B "fix-issue-37" 104 + run ../git-open "--issue" 105 + assert_output "https://github.com/paulirish/git-open/issues/37" 106 + 107 + git checkout -B "fix-issue-38" 108 + run ../git-open "-i" 109 + assert_output "https://github.com/paulirish/git-open/issues/38" 110 + } 111 + 112 + @test "gh: gist" { 113 + git remote set-url origin "[email protected]:2d84a6db1b41b4020685.git" 114 + run ../git-open 115 + assert_output "https://gist.github.com/2d84a6db1b41b4020685" 116 + } 117 + 118 + @test "basic: # and % in branch names are URL encoded" { 119 + # https://github.com/paulirish/git-open/pull/24 120 + git checkout -B "issue-#42" 121 + run ../git-open 122 + assert_output "https://github.com/paulirish/git-open/tree/issue-%2342" 123 + 124 + git checkout -B "just-50%" 125 + run ../git-open 126 + assert_output "https://github.com/paulirish/git-open/tree/just-50%25" 127 + } 128 + 129 + @test "basic: tracked remote is default" { 130 + # https://github.com/paulirish/git-open/issues/65 131 + 132 + # create a local git repo I can push to 133 + remote_name="sandboxremote" 134 + remote_url="[email protected]:userfork/git-open.git" 135 + 136 + # ideally we'd set a real upstream branch, but that's not possible without 137 + # pull/push'ing over the network. So we're cheating and just setting the 138 + # branch.<branch>.remote config 139 + # https://github.com/paulirish/git-open/pull/88#issuecomment-339813145 140 + git remote add $remote_name $remote_url 141 + git config --local --add branch.master.remote $remote_name 142 + 143 + run ../git-open 144 + assert_output "https://github.com/userfork/git-open" 145 + 146 + git config --local --add branch.master.remote origin 147 + run ../git-open 148 + assert_output "https://github.com/paulirish/git-open" 149 + } 150 + 151 + @test "basic: https url can contain port" { 152 + git remote set-url origin "https://github.com:99/user/repo.git" 153 + run ../git-open 154 + assert_output "https://github.com:99/user/repo" 155 + } 156 + 157 + @test "basic: ssh url has port removed from http url" { 158 + git remote set-url origin "ssh://github.com:22/user/repo.git" 159 + run ../git-open 160 + assert_output "https://github.com/user/repo" 161 + } 162 + 163 + @test "basic: http url scheme is preserved" { 164 + git remote set-url origin "http://github.com/user/repo.git" 165 + run ../git-open 166 + assert_output "http://github.com/user/repo" 167 + } 168 + 169 + 170 + ## 171 + ## Bitbucket 172 + ## 173 + 174 + @test "bitbucket: basic" { 175 + git remote set-url origin "[email protected]:paulirish/crbug-extension.git" 176 + run ../git-open 177 + assert_output --partial "https://bitbucket.org/paulirish/crbug-extension" 178 + } 179 + 180 + @test "bitbucket: non-origin remote" { 181 + # https://github.com/paulirish/git-open/pull/4 182 + git remote add bbclone "[email protected]:rwhitbeck/git-open.git" 183 + run ../git-open "bbclone" 184 + assert_output "https://bitbucket.org/rwhitbeck/git-open" 185 + } 186 + 187 + @test "bitbucket: open source view" { 188 + # https://github.com/paulirish/git-open/pull/26 189 + git remote set-url origin "https://bitbucket.org/kisom/consbri.git" 190 + git checkout -B "devel" 191 + run ../git-open 192 + refute_output --partial "//kisom" 193 + assert_output "https://bitbucket.org/kisom/consbri/src?at=devel" 194 + } 195 + 196 + @test "bitbucket: open source view with a slash/branch" { 197 + # https://github.com/paulirish/git-open/pull/26 198 + # see https://github.com/paulirish/git-open/issues/80 for feat/branchname issues 199 + git remote set-url origin "https://bitbucket.org/guyzmo/git-repo.git" 200 + git checkout -B "bugfix/conftest_fix" 201 + run ../git-open 202 + assert_output --partial "https://bitbucket.org/guyzmo/git-repo/src" 203 + # BB appears to be fine with both literal or URL-encoded forward slash 204 + assert_output --partial "?at=bugfix/conftest_fix" 205 + } 206 + 207 + @test "bitbucket: ssh:// clone urls" { 208 + # https://github.com/paulirish/git-open/pull/36 209 + git remote set-url origin "ssh://[email protected]/lbesson/bin.git" 210 + run ../git-open 211 + assert_output "https://bitbucket.org/lbesson/bin" 212 + } 213 + 214 + @test "bitbucket: no username@ in final url" { 215 + # https://github.com/paulirish/git-open/pull/69 216 + git remote set-url origin "https://[email protected]/trend_rand/test-repo.git" 217 + run ../git-open 218 + refute_output --partial "@" 219 + } 220 + 221 + @test "bitbucket: Bitbucket Server" { 222 + # https://github.com/paulirish/git-open/issues/77#issuecomment-309044010 223 + git remote set-url origin "https://[email protected]/scm/ppp/rrr.git" 224 + run ../git-open 225 + 226 + # any of the following are acceptable 227 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr" || 228 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=master" || 229 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse/?at=refs%2Fheads%2Fmaster" 230 + } 231 + 232 + @test "bitbucket: Bitbucket Server branch" { 233 + # https://github.com/paulirish/git-open/issues/80 234 + git remote set-url origin "https://[email protected]/scm/ppp/rrr.git" 235 + git checkout -B "develop" 236 + run ../git-open 237 + 238 + # The following query args work with BB Server: 239 + # at=refs%2Fheads%2Fdevelop, at=develop, at=refs/heads/develop 240 + # However /src/develop does not (unlike bitbucket.org) 241 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=develop" || 242 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 243 + assert_output "https://mybb.domain.com/projects/ppp/repos/rrr/browse?at=refs/heads/develop" 244 + 245 + refute_output --partial "/src/develop" 246 + } 247 + 248 + 249 + @test "bitbucket: Bitbucket Server private user repos" { 250 + # https://github.com/paulirish/git-open/pull/83#issuecomment-309968538 251 + git remote set-url origin "https://mybb.domain.com/scm/~first.last/rrr.git" 252 + git checkout -B "develop" 253 + run ../git-open 254 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=develop" || 255 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 256 + assert_output "https://mybb.domain.com/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" 257 + 258 + } 259 + 260 + 261 + @test "bitbucket: Bitbucket Server with different root context" { 262 + # https://github.com/paulirish/git-open/pull/15 263 + git remote set-url origin "https://[email protected]/git/scm/ppp/test-repo.git" 264 + run ../git-open 265 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo" || 266 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=master" || 267 + assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster" 268 + } 269 + 270 + 271 + @test "bitbucket: Bitbucket Server with different root context with multiple parts" { 272 + # https://github.com/paulirish/git-open/pull/15 273 + git remote set-url origin "https://[email protected]/really/long/root/context/scm/ppp/test-repo.git" 274 + run ../git-open 275 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo" || 276 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=master" || 277 + assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster" 278 + } 279 + 280 + 281 + @test "bitbucket: Bitbucket Server private user repos with different root context" { 282 + # https://github.com/paulirish/git-open/pull/83#issuecomment-309968538 283 + git remote set-url origin "https://mybb.domain.com/root/context/scm/~first.last/rrr.git" 284 + git checkout -B "develop" 285 + run ../git-open 286 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=develop" || 287 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || 288 + assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" 289 + } 290 + 291 + 292 + ## 293 + ## GitLab 294 + ## 295 + 296 + @test "gitlab: default ssh origin style" { 297 + # https://github.com/paulirish/git-open/pull/55 298 + git remote set-url origin "[email protected]:user/repo" 299 + run ../git-open 300 + assert_output "https://gitlab.example.com/user/repo" 301 + } 302 + 303 + @test "gitlab: ssh://git@ origin" { 304 + # https://github.com/paulirish/git-open/pull/51 305 + git remote set-url origin "ssh://[email protected]/user/repo" 306 + run ../git-open 307 + assert_output "https://gitlab.domain.com/user/repo" 308 + refute_output --partial "//user" 309 + } 310 + 311 + @test "gitlab: separate domains" { 312 + # https://github.com/paulirish/git-open/pull/56 313 + git remote set-url origin "[email protected]:namespace/project.git" 314 + git config --local --add "open.https://git.example.com.domain" "gitlab.example.com" 315 + run ../git-open 316 + assert_output "https://gitlab.example.com/namespace/project" 317 + } 318 + 319 + @test "gitlab: special domain and path" { 320 + git remote set-url origin "ssh://[email protected]:7000/XXX/YYY.git" 321 + git config --local --add "open.https://git.example.com.domain" "repo.intranet/subpath" 322 + git config --local --add "open.https://git.example.com.protocol" "http" 323 + 324 + run ../git-open 325 + assert_output "http://repo.intranet/subpath/XXX/YYY" 326 + refute_output --partial "https://" 327 + } 328 + 329 + @test "gitlab: different port" { 330 + # https://github.com/paulirish/git-open/pull/76 331 + git remote set-url origin "ssh://[email protected]:7000/XXX/YYY.git" 332 + run ../git-open 333 + assert_output "https://git.example.com/XXX/YYY" 334 + refute_output --partial ":7000" 335 + 336 + git remote set-url origin "https://git.example.com:7000/XXX/YYY.git" 337 + run ../git-open 338 + assert_output "https://git.example.com:7000/XXX/YYY" 339 + } 340 + 341 + ## 342 + ## Visual Studio Team Services 343 + ## 344 + 345 + @test "vsts: https url" { 346 + git remote set-url origin "https://gitopen.visualstudio.com/Project/_git/Repository" 347 + run ../git-open 348 + assert_output --partial "https://gitopen.visualstudio.com/Project/_git/Repository" 349 + } 350 + 351 + @test "vsts: ssh url" { 352 + git remote add vsts_ssh "ssh://[email protected]:22/Project/_git/Repository" 353 + run ../git-open "vsts_ssh" 354 + assert_output "https://gitopen.visualstudio.com/Project/_git/Repository" 355 + } 356 + 357 + @test "vsts: on-premises tfs http url" { 358 + git remote set-url origin "http://tfs.example.com:8080/Project/_git/Repository" 359 + run ../git-open 360 + assert_output --partial "http://tfs.example.com:8080/Project/_git/Repository" 361 + } 362 + 363 + @test "vsts: branch" { 364 + git remote set-url origin "ssh://[email protected]:22/_git/Repository" 365 + git checkout -B "mybranch" 366 + run ../git-open 367 + assert_output "https://gitopen.visualstudio.com/_git/Repository?version=GBmybranch" 368 + } 369 + 370 + @test "vsts: on-premises tfs branch" { 371 + git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository" 372 + git checkout -B "mybranch" 373 + run ../git-open 374 + assert_output "http://tfs.example.com:8080/Project/Folder/_git/Repository?version=GBmybranch" 375 + } 376 + 377 + @test "vsts: issue" { 378 + git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository" 379 + git checkout -B "bugfix-36" 380 + run ../git-open "--issue" 381 + assert_output "http://tfs.example.com:8080/Project/Folder/_workitems?id=36" 382 + } 383 +