Skip to content

Commit 3093960

Browse files
committed
exposing repo root folder as part of the info (fixes #7)
1 parent 4ec85bb commit 3093960

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ function findTag(gitPath, sha) {
8989
}
9090

9191
module.exports = function(gitPath) {
92-
if (!gitPath) { gitPath = findRepo(); }
92+
gitPath = findRepo(gitPath);
9393

9494
var result = {
9595
sha: null,
9696
abbreviatedSha: null,
9797
branch: null,
98-
tag: null
98+
tag: null,
99+
root: path.resolve(gitPath, '..')
99100
};
100101

101102
try {

tests/index.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ describe('git-repo-info', function() {
5252
var foundPath = repoInfo._findRepo();
5353
assert.equal(foundPath, path.join(repoRoot, gitDir));
5454
});
55+
56+
it('finds a repo 2 levels up (without an argument)', function() {
57+
process.chdir(path.join(repoRoot, 'foo', 'bar'));
58+
59+
var foundPath = repoInfo._findRepo();
60+
assert.equal(foundPath, path.join(repoRoot, gitDir));
61+
});
5562
});
5663

5764
describe('repoInfo', function() {
@@ -63,7 +70,8 @@ describe('git-repo-info', function() {
6370
branch: 'master',
6471
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745',
6572
abbreviatedSha: '5359aabd38',
66-
tag: null
73+
tag: null,
74+
root: repoRoot
6775
};
6876

6977
assert.deepEqual(result, expected);
@@ -77,7 +85,8 @@ describe('git-repo-info', function() {
7785
branch: null,
7886
sha: '9dac893d5a83c02344d91e79dad8904889aeacb1',
7987
abbreviatedSha: '9dac893d5a',
80-
tag: null
88+
tag: null,
89+
root: repoRoot
8190
};
8291

8392
assert.deepEqual(result, expected);
@@ -92,7 +101,8 @@ describe('git-repo-info', function() {
92101
branch: 'master',
93102
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745',
94103
abbreviatedSha: '5359aabd38',
95-
tag: 'my-tag'
104+
tag: 'my-tag',
105+
root: repoRoot
96106
};
97107

98108
assert.deepEqual(result, expected);
@@ -106,7 +116,8 @@ describe('git-repo-info', function() {
106116
branch: 'master',
107117
sha: 'c1ee41c325d54f410b133e0018c7a6b1316f6cda',
108118
abbreviatedSha: 'c1ee41c325',
109-
tag: 'awesome-tag'
119+
tag: 'awesome-tag',
120+
root: repoRoot
110121
};
111122

112123
assert.deepEqual(result, expected);
@@ -120,7 +131,8 @@ describe('git-repo-info', function() {
120131
branch: 'master',
121132
sha: 'c1ee41c325d54f410b133e0018c7a6b1316f6cda',
122133
abbreviatedSha: 'c1ee41c325',
123-
tag: 'awesome-tag'
134+
tag: 'awesome-tag',
135+
root: repoRoot
124136
};
125137

126138
assert.deepEqual(result, expected);
@@ -135,7 +147,8 @@ describe('git-repo-info', function() {
135147
branch: 'master',
136148
sha: 'c1ee41c325d54f410b133e0018c7a6b1316f6cda',
137149
abbreviatedSha: 'c1ee41c325',
138-
tag: 'awesome-tag'
150+
tag: 'awesome-tag',
151+
root: repoRoot
139152
};
140153

141154
assert.deepEqual(result, expected);
@@ -150,10 +163,25 @@ describe('git-repo-info', function() {
150163
branch: 'feature/branch/with/slashes',
151164
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745',
152165
abbreviatedSha: '5359aabd38',
153-
tag: null
166+
tag: null,
167+
root: repoRoot
154168
};
155169

156170
assert.deepEqual(result, expected);
157171
});
158172
});
173+
174+
describe('repoInfo().root', function() {
175+
var repoRoot = path.join(testFixturesPath, 'nested-repo');
176+
177+
it('finds a repo from cwd (2 levels up)', function() {
178+
process.chdir(path.join(repoRoot, 'foo', 'bar'));
179+
assert.equal(repoInfo().root, repoRoot);
180+
});
181+
182+
it('finds a repo with an argument', function() {
183+
assert.equal(repoInfo(path.join(repoRoot, 'foo', 'bar')).root, repoRoot);
184+
});
185+
186+
});
159187
});

0 commit comments

Comments
 (0)