Skip to content

Commit c5de586

Browse files
committed
Merge pull request #5 from AKPWebDesign/patch-1
Add support for branches with slashes in their names. Fixes #3.
2 parents 8bf847d + ad66da0 commit c5de586

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ module.exports = function(gitPath) {
103103

104104
if (fs.existsSync(headFilePath)) {
105105
var headFile = fs.readFileSync(headFilePath, {encoding: 'utf8'});
106-
var branchName = headFile.split('/').slice(-1)[0].trim();
106+
var branchName = headFile.split('/').slice(2).join('/').trim();
107+
if (!branchName) {
108+
branchName = headFile.split('/').slice(-1)[0].trim();
109+
}
107110
var refPath = headFile.split(' ')[1];
108111

109112
// Find branch and SHA
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/feature/branch/with/slashes
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5359aabd3872d9ffd160712e9615c5592dfe6745
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5359aabd3872d9ffd160712e9615c5592dfe6745

tests/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,19 @@ describe('git-repo-info', function() {
127127
assert.deepEqual(result, expected);
128128
});
129129
}
130+
131+
it('returns an object with repo info, including the full branch name, if the branch name includes any slashes', function() {
132+
var repoRoot = path.join(testFixturesPath, 'branch-with-slashes');
133+
var result = repoInfo(path.join(repoRoot, gitDir));
134+
135+
var expected = {
136+
branch: 'feature/branch/with/slashes',
137+
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745',
138+
abbreviatedSha: '5359aabd38',
139+
tag: null
140+
};
141+
142+
assert.deepEqual(result, expected);
143+
});
130144
});
131145
});

0 commit comments

Comments
 (0)