Skip to content

Commit

Permalink
Fix: should noop if info array has no values (closes #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
JPeer264 committed Jan 12, 2022
1 parent 0e26016 commit f42cee3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions __tests__/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ test('unknown commit hash', () => {
expect(!!latestInfo.error).toBe(true);
});

test('check up to date', () => {
const mergeInfo = gitCommitInfo({
cwd: path.join(fixtures, 'upToDate'),
commit: '31107b9051efe17e57c583937e027993860b11a9',
});

expect(mergeInfo.commit).toBe('31107b9051efe17e57c583937e027993860b11a9');
expect(mergeInfo.message).toBe('Initial commit');
});

test('merge conflict - named automatically', () => {
const mergeInfo = gitCommitInfo({
cwd: path.join(fixtures, 'merge'),
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const gitCommitInfo = (options: GitCommitInfoOptions = {}): GitCommitInfoResult
const info = stdout
.split('\n')
.filter((entry) => entry.length !== 0);
const mergeIndex = info[1].indexOf('Merge') === -1 ? 0 : 1;
const mergeIndex = info[1]?.indexOf('Merge') === -1 ? 0 : 1;

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

0 comments on commit f42cee3

Please sign in to comment.