Skip to content

Commit a273688

Browse files
danseethalerbugthesystem
authored andcommitted
Adds dynamic remote selection based on branch #64 (#66)
1 parent 29788d5 commit a273688

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/extension.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,34 @@ function getGitProviderLink(cb, fileFsPath, lines, pr) {
2525
git({
2626
cwd: repoDir
2727
}, function (err, config) {
28-
const rawUri = config['remote \"origin\"'].url;
29-
var provider = null;
30-
31-
try {
32-
provider = gitProvider(rawUri);
33-
} catch (e) {
34-
let errmsg = e.toString();
35-
Window.showWarningMessage(`Unknown Git provider. ${errmsg}`);
36-
return;
37-
}
3828

39-
gitRev.branch(cwd, function (branchErr, branch) {
40-
if (branchErr || !branch)
41-
branch = 'master';
29+
gitRev.branch(cwd, function(branchErr, branch) {
30+
var rawUri,
31+
configuredBranch,
32+
provider = null,
33+
remoteName;
34+
35+
if (branchErr || !branch) branch = 'master';
36+
37+
// Check to see if the branch has a configured remote
38+
configuredBranch = config[`branch "${branch}"`];
39+
40+
if (!configuredBranch) {
41+
Window.showWarningMessage(`No remote found on branch.`);
42+
return;
43+
}
44+
45+
// Use the current branch's configured remote
46+
remoteName = configuredBranch.remote;
47+
rawUri = config[`remote "${remoteName}"`].url;
48+
49+
try {
50+
provider = gitProvider(rawUri);
51+
} catch (e) {
52+
let errmsg = e.toString();
53+
Window.showWarningMessage(`Unknown Git provider. ${errmsg}`);
54+
return;
55+
}
4256

4357
let subdir = fileFsPath ? fileFsPath.substring(workspace.rootPath.length).replace(/\"/g, "") : undefined;
4458

0 commit comments

Comments
 (0)