Skip to content

Commit 9b1a86f

Browse files
martynchamberlinbugthesystem
authored andcommitted
Prefer SHA to branch and give option to right-click (#78)
1 parent 7a68b4b commit 9b1a86f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
}
9292
],
9393
"menus": {
94+
"editor/context": [
95+
{
96+
"command": "extension.openInGitHub"
97+
}
98+
],
9499
"explorer/context": [
95100
{
96101
"command": "extension.openInGitHub"

src/extension.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ function getGitProviderLink(cb, fileFsPath, lines, pr) {
2828
.then(readConfigFile)
2929
.then(config => {
3030

31-
gitRev.branch(repoDir, function (branchErr, branch) {
31+
gitRev.long(repoDir, function (branchErr, sha) {
3232
var rawUri,
3333
configuredBranch,
3434
provider = null,
3535
remoteName;
3636

37-
if (branchErr || !branch) branch = 'master';
37+
var branch = 'master';
3838

3939
// Check to see if the branch has a configured remote
4040
configuredBranch = config[`branch "${branch}"`];
@@ -78,12 +78,12 @@ function getGitProviderLink(cb, fileFsPath, lines, pr) {
7878
} else {
7979
if (lines) {
8080
if (lines[0] == lines[1]) {
81-
cb(provider.webUrl(branch, subdir, lines[0]));
81+
cb(provider.webUrl(sha, subdir, lines[0]));
8282
} else {
83-
cb(provider.webUrl(branch, subdir, lines[0], lines[1]));
83+
cb(provider.webUrl(sha, subdir, lines[0], lines[1]));
8484
}
8585
} else {
86-
cb(provider.webUrl(branch, subdir));
86+
cb(provider.webUrl(sha, subdir));
8787
}
8888
}
8989
});
@@ -177,10 +177,10 @@ function branchOnCallingContext(args, cb, pr) {
177177
return getGitProviderPullRequest(args, cb);
178178
}
179179

180-
if (args && args.fsPath) {
181-
getGitProviderLinkForFile(args.fsPath, cb);
182-
} else if (Window.activeTextEditor) {
180+
if (Window.activeTextEditor) {
183181
getGitProviderLinkForCurrentEditorLines(cb);
182+
} else if (args && args.fsPath) {
183+
getGitProviderLinkForFile(args.fsPath, cb);
184184
} else {
185185
// TODO: This missed in code review so should be refactored, it is broken.
186186
getGitProviderLinkForRepo(cb);

0 commit comments

Comments
 (0)