From 2eda81768676aa575246d56b2624e2deccda0bdf Mon Sep 17 00:00:00 2001 From: Steve King Date: Sat, 23 Sep 2023 15:05:29 +0300 Subject: [PATCH 1/2] 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[]) { From ebbfe8eb8f19323e069ce5512731dc6cb5d39973 Mon Sep 17 00:00:00 2001 From: Steve King Date: Sat, 23 Sep 2023 15:12:26 +0300 Subject: [PATCH 2/2] Fix test, update matrix to include node@20 --- .github/workflows/ci.yml | 2 +- simple-git/test/unit/log.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57c61b49..9ab5c9e7 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@v3 - name: Use Node.js ${{ matrix.node-version }} diff --git a/simple-git/test/unit/log.spec.ts b/simple-git/test/unit/log.spec.ts index 4d8d59b8..5e9fcd4b 100644 --- a/simple-git/test/unit/log.spec.ts +++ b/simple-git/test/unit/log.spec.ts @@ -55,8 +55,8 @@ describe('log', () => { '--follow', '--fixed-strings', '--', - 'file2', - 'index.js' + 'index.js', + 'file2' ); });