From 6830e6b98c91a035c723d37aad90392716995568 Mon Sep 17 00:00:00 2001 From: Yuichi Tanikawa Date: Sat, 23 Apr 2016 18:21:56 +0900 Subject: [PATCH] `openRepository` opens remote branch tree urls by default --- lib/github-file.coffee | 12 +++++-- spec/fixtures/some-branch.git/HEAD | 1 + spec/fixtures/some-branch.git/config | 13 +++++++ spec/fixtures/some-branch.git/index | Bin 0 -> 186 bytes .../5c/dc5a2508dfc832223df221a8e55fb6ccf95932 | Bin 0 -> 50 bytes .../80/b7897ceb6bd7531708509b50afeab36a4b73fd | 1 + .../98/4f6dfa5e1ac016cb4e4d11f39343efb3c27d7f | Bin 0 -> 57 bytes .../bf/b04df9a5bf7ad257575599558b54b3fc335f24 | Bin 0 -> 301 bytes .../some-branch.git/refs/heads/some-branch | 1 + spec/github-file-spec.coffee | 32 ++++++++++++++++++ 10 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/some-branch.git/HEAD create mode 100644 spec/fixtures/some-branch.git/config create mode 100644 spec/fixtures/some-branch.git/index create mode 100644 spec/fixtures/some-branch.git/objects/5c/dc5a2508dfc832223df221a8e55fb6ccf95932 create mode 100644 spec/fixtures/some-branch.git/objects/80/b7897ceb6bd7531708509b50afeab36a4b73fd create mode 100644 spec/fixtures/some-branch.git/objects/98/4f6dfa5e1ac016cb4e4d11f39343efb3c27d7f create mode 100644 spec/fixtures/some-branch.git/objects/bf/b04df9a5bf7ad257575599558b54b3fc335f24 create mode 100644 spec/fixtures/some-branch.git/refs/heads/some-branch diff --git a/lib/github-file.coffee b/lib/github-file.coffee index 116a897..20bf9d1 100644 --- a/lib/github-file.coffee +++ b/lib/github-file.coffee @@ -79,8 +79,8 @@ class GitHubFile openRepository: -> @isOpenable().then (isOpenable) => if isOpenable - @gitHubRepoUrl().then (gitHubRepoUrl) => - @openUrlInBrowser(gitHubRepoUrl) + @treeUrl().then (treeUrl) => + @openUrlInBrowser(treeUrl) else @reportValidationErrors() @@ -170,6 +170,14 @@ class GitHubFile .then ([gitHubRepoUrl, branchName]) => "#{gitHubRepoUrl}/compare/#{@encodeSegments(branchName)}" + treeUrl: -> + Promise.all([@gitHubRepoUrl(), @remoteBranchName()]) + .then ([gitHubRepoUrl, remoteBranchName]) -> + if remoteBranchName isnt 'master' + "#{gitHubRepoUrl}/tree/#{remoteBranchName}" + else + gitHubRepoUrl + encodeSegments: (segments='') -> segments = segments.split('/') segments = segments.map (segment) -> encodeURIComponent(segment) diff --git a/spec/fixtures/some-branch.git/HEAD b/spec/fixtures/some-branch.git/HEAD new file mode 100644 index 0000000..37c771a --- /dev/null +++ b/spec/fixtures/some-branch.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/some-branch diff --git a/spec/fixtures/some-branch.git/config b/spec/fixtures/some-branch.git/config new file mode 100644 index 0000000..0ce88ff --- /dev/null +++ b/spec/fixtures/some-branch.git/config @@ -0,0 +1,13 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = false +[remote "origin"] + url = https://github.com/some-user/some-repo.git + fetch = +refs/heads/*:refs/remotes/origin/* +[branch "some-branch"] + remote = origin + merge = refs/heads/some-branch diff --git a/spec/fixtures/some-branch.git/index b/spec/fixtures/some-branch.git/index new file mode 100644 index 0000000000000000000000000000000000000000..ac609f4c8f6f513a3cdf69ba61a103b64c7afaf1 GIT binary patch literal 186 zcmZ?q402{*U|<4b#&Bux1R%`-qZt_(SQxn@!WbADmjI=|0;NQNO2zhX@cp@Tf7PY% z@X(o|-65O*7{{wHh!*GPrs}3-7U_c-X_+~xdbuee;}}AMTwQ^b6@#IIAy>?uC{>R8 zCybPAKPj$w8o%w#&qyPfR-gg{t{MKhzv840h@JNH75qHe`TgcYwe^k18Uu?b+St~Z Pzw6Y9HP?44+`k9_w^BQN literal 0 HcmV?d00001 diff --git a/spec/fixtures/some-branch.git/objects/5c/dc5a2508dfc832223df221a8e55fb6ccf95932 b/spec/fixtures/some-branch.git/objects/5c/dc5a2508dfc832223df221a8e55fb6ccf95932 new file mode 100644 index 0000000000000000000000000000000000000000..1a76bd523334a1b7ea1cbdcae98b4d8265d9fc9e GIT binary patch literal 50 zcmV-20L}k+0V^p=O;s>9WiT-S0)^uI+*I9^%p!&v{<**6qz;Ik_VX3|JlXmE=0mmh I05gRUsV$xu@c;k- literal 0 HcmV?d00001 diff --git a/spec/fixtures/some-branch.git/objects/80/b7897ceb6bd7531708509b50afeab36a4b73fd b/spec/fixtures/some-branch.git/objects/80/b7897ceb6bd7531708509b50afeab36a4b73fd new file mode 100644 index 0000000..1d0efa7 --- /dev/null +++ b/spec/fixtures/some-branch.git/objects/80/b7897ceb6bd7531708509b50afeab36a4b73fd @@ -0,0 +1 @@ +x¥ÍA‚0@Q×=Å\@S¦´ 1nué Ê´µ5@ ÷ÃܾÅÿ\§©4Îd‰ˆ“GÒ6$¶MHˆ·‘( -srä *¿J® Üý§ÎðXCßúg‘¼××O—O\§ 4¦ë\g\KpÔg­Õ¦ÛXâ u›‹?ÂÞR_â@Ñ \ No newline at end of file diff --git a/spec/fixtures/some-branch.git/objects/98/4f6dfa5e1ac016cb4e4d11f39343efb3c27d7f b/spec/fixtures/some-branch.git/objects/98/4f6dfa5e1ac016cb4e4d11f39343efb3c27d7f new file mode 100644 index 0000000000000000000000000000000000000000..f9c9b28b83f4de0ac3fbf032899be42ee1e9f56c GIT binary patch literal 57 zcmV-90LK4#0V^p=O;s>4U@$Z=Ff%bxD9+DK)lJLHN!80uVc5UH_vh06RhPoULuZC| Phiv|19IpZZjJpz^v~L=U literal 0 HcmV?d00001 diff --git a/spec/fixtures/some-branch.git/objects/bf/b04df9a5bf7ad257575599558b54b3fc335f24 b/spec/fixtures/some-branch.git/objects/bf/b04df9a5bf7ad257575599558b54b3fc335f24 new file mode 100644 index 0000000000000000000000000000000000000000..53983f2691f69ff12668e666afffb81224f4d70d GIT binary patch literal 301 zcmV+|0n+|>0ZozJal;@Gg!8N_wg6i%Ng8koNg6oNSti09!%sZ!J_jg{Ul?Gx{dO1Q z#o+z*?d3#P0$j}XibcF6WLH2}F31yObjgdpvlnMK4v3Prsofl&Ax%6| zuv`l1CYMB4hi|!g80Pa>x*bE_qXBoPUC*%hca)kozALF(1%DllsM*3ngLVr|NvS=9 zHjv5)*c5a~VmtDk=jqgtdwAcB^d}v1K(o3gsbRrb&t8N6HHZscwdVnB{#C8l^{9N1 zM+4pJ;}fi;z{|+`PegR runs -> expect(githubFile.openUrlInBrowser).toHaveBeenCalledWith \ 'https://github.com/some-user/some-repo' + describe "when the branch is not master", -> + fixtureName = 'some-branch' + + beforeEach -> + setupWorkingDir(fixtureName) + setupGithubFile() + + afterEach -> + teardownWorkingDirAndRestoreFixture(fixtureName) + + it "opens the GitHub.com tree URL for the branch", -> + spyOn(githubFile, 'openUrlInBrowser') + waitsForPromise -> githubFile.openRepository() + runs -> expect(githubFile.openUrlInBrowser).toHaveBeenCalledWith \ + 'https://github.com/some-user/some-repo/tree/some-branch' + + describe "when the local branch is not tracked", -> + fixtureName = 'non-tracked-branch' + + beforeEach -> + setupWorkingDir(fixtureName) + setupGithubFile() + + afterEach -> + teardownWorkingDirAndRestoreFixture(fixtureName) + + it "opens the GitHub.com reposiotry URL", -> + spyOn(githubFile, 'openUrlInBrowser') + waitsForPromise -> githubFile.openRepository() + runs -> expect(githubFile.openUrlInBrowser).toHaveBeenCalledWith \ + 'https://github.com/some-user/some-repo' + describe "openIssues", -> describe 'when the file is openable on GitHub.com', -> fixtureName = 'github-remote'