Skip to content

Commit 0c22fb7

Browse files
authored
Merge pull request #35 from Emrvb/master
Fixed issue with finding submodule repo when gitPath is specified
2 parents 3201ab0 + 357163b commit 0c22fb7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ function findRepoHandleLinkedWorktree(gitPath) {
2525
// whether it's a linked worktree git dir, or a submodule dir
2626

2727
var linkedGitDir = fs.readFileSync(gitPath).toString();
28+
var absolutePath=path.resolve(path.dirname(gitPath));
2829
var worktreeGitDirUnresolved = /gitdir: (.*)/.exec(linkedGitDir)[1];
29-
var worktreeGitDir = path.resolve(worktreeGitDirUnresolved);
30+
var worktreeGitDir = path.resolve(absolutePath,worktreeGitDirUnresolved);
3031
var commonDirPath = path.join(worktreeGitDir, 'commondir');
3132
if (fs.existsSync(commonDirPath)) {
3233
// this directory contains a `commondir` file; we're within a linked

tests/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ describe('git-repo-info', function() {
9494
commonGitDir: path.join(testFixturesPath, 'submodule', 'dot-git', 'modules', 'my-submodule'),
9595
});
9696
});
97+
98+
it('finds a repo via submodule on a specific path', function() {
99+
process.chdir(path.join(testFixturesPath, 'submodule'));
100+
101+
var foundPathInfo = repoInfo._findRepo('my-submodule');
102+
assert.deepEqual(foundPathInfo, {
103+
worktreeGitDir: path.join(testFixturesPath, 'submodule', 'dot-git', 'modules', 'my-submodule'),
104+
commonGitDir: path.join(testFixturesPath, 'submodule', 'dot-git', 'modules', 'my-submodule'),
105+
});
106+
});
97107
});
98108

99109
describe('repoInfo', function() {
@@ -355,6 +365,29 @@ describe('git-repo-info', function() {
355365

356366
assert.deepEqual(result, expected);
357367
});
368+
369+
it('returns an object for repo info for submodule on a specific path', function() {
370+
process.chdir(path.join(testFixturesPath, 'submodule'));
371+
var result = repoInfo('my-submodule');
372+
373+
var expected = {
374+
branch: null,
375+
sha: '409372f3bd07c11bfacee3963f48571d675268d7',
376+
abbreviatedSha: '409372f3bd',
377+
tag: null,
378+
committer: null,
379+
committerDate: null,
380+
author: null,
381+
authorDate: null,
382+
commitMessage: null,
383+
// This is a pretty meaningless "root" path. The other information is
384+
// correct, but we do not have full support for submodules at the
385+
// moment.
386+
root: path.join(testFixturesPath, 'submodule', 'dot-git', 'modules')
387+
};
388+
389+
assert.deepEqual(result, expected);
390+
});
358391
});
359392

360393
describe('repoInfo().root', function() {

0 commit comments

Comments
 (0)