From 2eda81768676aa575246d56b2624e2deccda0bdf Mon Sep 17 00:00:00 2001 From: Steve King Date: Sat, 23 Sep 2023 15:05:29 +0300 Subject: [PATCH] Use `pathspec` in `git.log` task to allow for the use of previously deleted files in the value of the `file` option. Prior to this change users of `git.log` may have been explicitly appending `'--': null` to their `git.log` options argument, this is no longer required but should not cause any interruption if not removed from the calling code. Closes #857 --- .changeset/sweet-steaks-draw.md | 5 ++++ simple-git/src/lib/tasks/log.ts | 3 ++- simple-git/test/unit/log.spec.ts | 44 +++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 .changeset/sweet-steaks-draw.md diff --git a/.changeset/sweet-steaks-draw.md b/.changeset/sweet-steaks-draw.md new file mode 100644 index 00000000..e38b6481 --- /dev/null +++ b/.changeset/sweet-steaks-draw.md @@ -0,0 +1,5 @@ +--- +'simple-git': minor +--- + +Use `pathspec` in `git.log` to allow use of previously deleted files in `file` argument diff --git a/simple-git/src/lib/tasks/log.ts b/simple-git/src/lib/tasks/log.ts index 3b927500..4779d126 100644 --- a/simple-git/src/lib/tasks/log.ts +++ b/simple-git/src/lib/tasks/log.ts @@ -1,6 +1,7 @@ import type { Options, StringTask } from '../types'; import type { LogResult, SimpleGit } from '../../../typings'; import { logFormatFromCommand } from '../args/log-format'; +import { pathspec } from '../args/pathspec'; import { COMMIT_BOUNDARY, createListLogSummaryParser, @@ -126,7 +127,7 @@ export function parseLogOptions( } if (filterString(opt.file)) { - suffix.push('--follow', opt.file); + command.push('--follow', pathspec(opt.file)); } appendTaskOptions(userOptions(opt as Options), command); diff --git a/simple-git/test/unit/log.spec.ts b/simple-git/test/unit/log.spec.ts index f2c76c54..4d8d59b8 100644 --- a/simple-git/test/unit/log.spec.ts +++ b/simple-git/test/unit/log.spec.ts @@ -1,5 +1,5 @@ import { promiseError } from '@kwsites/promise-result'; -import { LogResult, SimpleGit } from 'typings'; +import type { LogResult, SimpleGit } from 'typings'; import { assertExecutedCommands, assertExecutedCommandsContains, @@ -9,7 +9,7 @@ import { like, newSimpleGit, } from './__fixtures__'; -import { TaskConfigurationError } from '../..'; +import { TaskConfigurationError, pathspec } from '../..'; import { COMMIT_BOUNDARY, createListLogSummaryParser, @@ -33,8 +33,46 @@ describe('log', () => { assertExecutedCommands( 'log', `--pretty=format:${START_BOUNDARY}%H${COMMIT_BOUNDARY}`, + '--follow', + '--fixed-strings', + '--', + 'index.js' + ); + }); + + it('follow option works with explicit pathspec', async () => { + git.log({ + 'file': 'index.js', + 'format': { hash: '%H' }, + '--fixed-strings': null, + 'path': pathspec('file2'), + }); + await closeWithSuccess(); + + assertExecutedCommands( + 'log', + `--pretty=format:${START_BOUNDARY}%H${COMMIT_BOUNDARY}`, + '--follow', '--fixed-strings', + '--', + 'file2', + 'index.js' + ); + }); + + it('follow option works with pathspec workaround', async () => { + git.log({ + 'format': { hash: '%H' }, + 'file': 'index.js', + '--': null, + }); + await closeWithSuccess(); + + assertExecutedCommands( + 'log', + `--pretty=format:${START_BOUNDARY}%H${COMMIT_BOUNDARY}`, '--follow', + '--', 'index.js' ); }); @@ -542,7 +580,7 @@ ${START_BOUNDARY}207601debebc170830f2921acf2b6b27034c3b1f::2016-01-03 15:50:58 + git.log({ file: '/foo/bar.txt', n: 10 }); await closeWithSuccess(); - assertCommandAppended('--max-count=10', '--follow', '/foo/bar.txt'); + assertCommandAppended('--max-count=10', '--follow', '--', '/foo/bar.txt'); }); function assertCommandAppended(...things: string[]) {