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/.github/workflows/ci.yml b/.github/workflows/ci.yml index 858ad435..d31bd1e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [14, 16, 18, 19] + node-version: [14, 16, 18, 20] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} 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..5e9fcd4b 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', + '--', + 'index.js', + 'file2' + ); + }); + + 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[]) {