From f42cee30815e3da992a6a25c1f6cc64adf1148a0 Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Wed, 12 Jan 2022 22:45:40 +0100 Subject: [PATCH] Fix: should noop if info array has no values (closes #14) --- __tests__/test.spec.ts | 10 ++++++++++ index.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/__tests__/test.spec.ts b/__tests__/test.spec.ts index 57b81f0..5a97684 100644 --- a/__tests__/test.spec.ts +++ b/__tests__/test.spec.ts @@ -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'), diff --git a/index.ts b/index.ts index 2f4cf74..9a381be 100644 --- a/index.ts +++ b/index.ts @@ -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);