Skip to content

Commit

Permalink
fix(version): use %aI to pull oldest commit author date
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Aug 8, 2022
1 parent 9f4fa45 commit e033e05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Expand Up @@ -63,7 +63,7 @@ describe('getOldestCommitSinceLastTag', () => {

expect(execSpy).toHaveBeenCalledWith(
'git',
['log', '--oneline', '--format="%h %cI"', '--reverse', '--max-parents=0', 'HEAD'],
['log', '--oneline', '--format="%h %aI"', '--reverse', '--max-parents=0', 'HEAD'],
execOpts
);
expect(result).toEqual({ commitDate: '2022-07-01T00:01:02-04:00', commitHash: 'abcbeef' });
Expand All @@ -82,16 +82,16 @@ describe('getOldestCommitSinceLastTag', () => {

const result = await getOldestCommitSinceLastTag(execOpts);

expect(execSpy).toHaveBeenCalledWith('git', ['log', 'v1.0.0..HEAD', '--format="%h %cI"', '--reverse'], execOpts);
expect(execSpy).toHaveBeenCalledWith('git', ['log', '-1', '--format="%h %cI"', 'v1.0.0'], execOpts);
expect(execSpy).toHaveBeenCalledWith('git', ['log', 'v1.0.0..HEAD', '--format="%h %aI"', '--reverse'], execOpts);
expect(execSpy).toHaveBeenCalledWith('git', ['log', '-1', '--format="%h %aI"', 'v1.0.0'], execOpts);
expect(result).toEqual({ commitDate: '2022-07-01T00:01:02-04:00', commitHash: 'deedbeaf' });
});

it('should expect a result with a tag date, hash and ref count', async () => {
const result = await getOldestCommitSinceLastTag(execOpts);
const execSpy = (execSync as jest.Mock).mockReturnValueOnce('"deadbeef 2022-07-01T00:01:02-04:00"');

expect(execSpy).toHaveBeenCalledWith('git', ['log', 'v1.0.0..HEAD', '--format="%h %cI"', '--reverse'], execOpts);
expect(execSpy).toHaveBeenCalledWith('git', ['log', 'v1.0.0..HEAD', '--format="%h %aI"', '--reverse'], execOpts);
expect(result).toEqual({ commitDate: '2022-07-01T00:01:02-04:00', commitHash: 'deadbeef' });
});
});
Expand Down
Expand Up @@ -49,17 +49,17 @@ export function getOldestCommitSinceLastTag(execOpts?: ExecOpts, includeMergedTa

if (lastTagName) {
log.silly('git', 'getCurrentBranchOldestCommitSinceLastTag');
let stdout = execSync('git', ['log', `${lastTagName}..HEAD`, '--format="%h %cI"', '--reverse'], execOpts);
let stdout = execSync('git', ['log', `${lastTagName}..HEAD`, '--format="%h %aI"', '--reverse'], execOpts);
if (!stdout) {
// in some occasion the previous git command might return nothing, in that case we'll return the tag detail instead
stdout = execSync('git', ['log', '-1', '--format="%h %cI"', lastTagName], execOpts);
stdout = execSync('git', ['log', '-1', '--format="%h %aI"', lastTagName], execOpts);
}
[commitResult] = stdout.split('\n');
} else {
log.silly('git', 'getCurrentBranchFirstCommit');
commitResult = execSync(
'git',
['log', '--oneline', '--format="%h %cI"', '--reverse', '--max-parents=0', 'HEAD'],
['log', '--oneline', '--format="%h %aI"', '--reverse', '--max-parents=0', 'HEAD'],
execOpts
);
}
Expand Down

0 comments on commit e033e05

Please sign in to comment.