Skip to content

Commit

Permalink
Merge pull request #948 from steveukx/fix/git-log-pathspec
Browse files Browse the repository at this point in the history
git.log should include a pathspec splitter automatically when using --follow
  • Loading branch information
steveukx committed Sep 23, 2023
2 parents 9000caf + ebbfe8e commit d84dd63
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-steaks-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'simple-git': minor
---

Use `pathspec` in `git.log` to allow use of previously deleted files in `file` argument
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion simple-git/src/lib/tasks/log.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -126,7 +127,7 @@ export function parseLogOptions<T extends Options>(
}

if (filterString(opt.file)) {
suffix.push('--follow', opt.file);
command.push('--follow', pathspec(opt.file));
}

appendTaskOptions(userOptions(opt as Options), command);
Expand Down
44 changes: 41 additions & 3 deletions simple-git/test/unit/log.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promiseError } from '@kwsites/promise-result';
import { LogResult, SimpleGit } from 'typings';
import type { LogResult, SimpleGit } from 'typings';
import {
assertExecutedCommands,
assertExecutedCommandsContains,
Expand All @@ -9,7 +9,7 @@ import {
like,
newSimpleGit,
} from './__fixtures__';
import { TaskConfigurationError } from '../..';
import { TaskConfigurationError, pathspec } from '../..';
import {
COMMIT_BOUNDARY,
createListLogSummaryParser,
Expand All @@ -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'
);
});
Expand Down Expand Up @@ -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[]) {
Expand Down

0 comments on commit d84dd63

Please sign in to comment.