Skip to content

Commit f42cee3

Browse files
committed
Fix: should noop if info array has no values (closes #14)
1 parent 0e26016 commit f42cee3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

__tests__/test.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ test('unknown commit hash', () => {
5656
expect(!!latestInfo.error).toBe(true);
5757
});
5858

59+
test('check up to date', () => {
60+
const mergeInfo = gitCommitInfo({
61+
cwd: path.join(fixtures, 'upToDate'),
62+
commit: '31107b9051efe17e57c583937e027993860b11a9',
63+
});
64+
65+
expect(mergeInfo.commit).toBe('31107b9051efe17e57c583937e027993860b11a9');
66+
expect(mergeInfo.message).toBe('Initial commit');
67+
});
68+
5969
test('merge conflict - named automatically', () => {
6070
const mergeInfo = gitCommitInfo({
6171
cwd: path.join(fixtures, 'merge'),

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const gitCommitInfo = (options: GitCommitInfoOptions = {}): GitCommitInfoResult
3939
const info = stdout
4040
.split('\n')
4141
.filter((entry) => entry.length !== 0);
42-
const mergeIndex = info[1].indexOf('Merge') === -1 ? 0 : 1;
42+
const mergeIndex = info[1]?.indexOf('Merge') === -1 ? 0 : 1;
4343

4444
const hash = (new RegExp(regex).exec(info[0]) || [])[1];
4545
const shortHash = hash.slice(0, 7);

0 commit comments

Comments
 (0)