Skip to content

Commit ac3309c

Browse files
committed
Merge branch 'master' into FixImagesOnVisualStudioCodeExtensionMarket
2 parents 7f6f10b + a7b7817 commit ac3309c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
},
8787
"dependencies": {
8888
"copy-paste": "^1.1.4",
89+
"find-parent-dir": "^0.3.0",
8990
"git-rev-2": "^0.1.0",
9091
"github-url-from-git": "^1.4.0",
9192
"open": "0.0.5",

src/extension.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var parse = require('github-url-from-git');
1414
var open = require('open');
1515
var copy = require('copy-paste').copy;
1616
var gitRev = require('git-rev-2');
17+
var findParentDir = require('find-parent-dir');
1718

1819
function formGitHubLink(parsedUri, branch, subdir, line) {
1920
if (subdir) {
@@ -34,9 +35,10 @@ function formVisualStudioLink(parsedUri, subdir, branch, line) {
3435

3536
function getGitHubLink(cb, fileFsPath, line) {
3637
var cwd = workspace.rootPath;
38+
var repoDir = findParentDir.sync(workspace.rootPath, '.git') || cwd;
3739

3840
git({
39-
cwd: cwd
41+
cwd: repoDir
4042
}, function (err, config) {
4143
var rawUri, parseOpts, parsedUri, branch, projectName,
4244
subdir, gitLink, scUrls, workspaceConfiguration;
@@ -63,14 +65,19 @@ function getGitHubLink(cb, fileFsPath, line) {
6365
parsedUri = rawUri;
6466
}
6567

66-
gitRev.branch( cwd, function (branchErr, branch) {
68+
gitRev.branch(cwd, function (branchErr, branch) {
6769
if (branchErr || !branch)
6870
branch = 'master';
6971

7072
projectName = parsedUri.substring(parsedUri.lastIndexOf("/") + 1, parsedUri.length);
71-
7273
subdir = fileFsPath ? fileFsPath.substring(workspace.rootPath.length).replace(/\"/g, "") : undefined;
7374

75+
if (repoDir !== cwd) {
76+
// The workspace directory is a subdirectory of the git repo folder so we need to prepend the the nested path
77+
var repoRelativePath = cwd.replace(repoDir, "/");
78+
subdir = repoRelativePath + subdir;
79+
}
80+
7481
if (parsedUri.startsWith(scUrls.github)) {
7582
gitLink = formGitHubLink(parsedUri, branch, subdir, line);
7683
} else if (parsedUri.startsWith(scUrls.bitbucket)) {
@@ -104,7 +111,7 @@ function getGitHubLinkForRepo(cb) {
104111
getGitHubLink(cb);
105112
}
106113

107-
function branchOnCallingContext(args, cb){
114+
function branchOnCallingContext(args, cb) {
108115
if (args && args.fsPath) {
109116
getGitHubLinkForFile(args.fsPath, cb);
110117
}
@@ -129,4 +136,4 @@ function activate(context) {
129136
context.subscriptions.push(commands.registerCommand('extension.copyGitHubLinkToClipboard', copyGitHubLinkToClipboard));
130137
}
131138

132-
exports.activate = activate;
139+
exports.activate = activate;

0 commit comments

Comments
 (0)