Skip to content

Commit d84dd63

Browse files
authored
Merge pull request #948 from steveukx/fix/git-log-pathspec
git.log should include a pathspec splitter automatically when using --follow
2 parents 9000caf + ebbfe8e commit d84dd63

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

.changeset/sweet-steaks-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'simple-git': minor
3+
---
4+
5+
Use `pathspec` in `git.log` to allow use of previously deleted files in `file` argument

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
node-version: [14, 16, 18, 19]
17+
node-version: [14, 16, 18, 20]
1818
steps:
1919
- uses: actions/checkout@v4
2020
- name: Use Node.js ${{ matrix.node-version }}

simple-git/src/lib/tasks/log.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Options, StringTask } from '../types';
22
import type { LogResult, SimpleGit } from '../../../typings';
33
import { logFormatFromCommand } from '../args/log-format';
4+
import { pathspec } from '../args/pathspec';
45
import {
56
COMMIT_BOUNDARY,
67
createListLogSummaryParser,
@@ -126,7 +127,7 @@ export function parseLogOptions<T extends Options>(
126127
}
127128

128129
if (filterString(opt.file)) {
129-
suffix.push('--follow', opt.file);
130+
command.push('--follow', pathspec(opt.file));
130131
}
131132

132133
appendTaskOptions(userOptions(opt as Options), command);

simple-git/test/unit/log.spec.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { promiseError } from '@kwsites/promise-result';
2-
import { LogResult, SimpleGit } from 'typings';
2+
import type { LogResult, SimpleGit } from 'typings';
33
import {
44
assertExecutedCommands,
55
assertExecutedCommandsContains,
@@ -9,7 +9,7 @@ import {
99
like,
1010
newSimpleGit,
1111
} from './__fixtures__';
12-
import { TaskConfigurationError } from '../..';
12+
import { TaskConfigurationError, pathspec } from '../..';
1313
import {
1414
COMMIT_BOUNDARY,
1515
createListLogSummaryParser,
@@ -33,8 +33,46 @@ describe('log', () => {
3333
assertExecutedCommands(
3434
'log',
3535
`--pretty=format:${START_BOUNDARY}%H${COMMIT_BOUNDARY}`,
36+
'--follow',
3637
'--fixed-strings',
38+
'--',
39+
'index.js'
40+
);
41+
});
42+
43+
it('follow option works with explicit pathspec', async () => {
44+
git.log({
45+
'file': 'index.js',
46+
'format': { hash: '%H' },
47+
'--fixed-strings': null,
48+
'path': pathspec('file2'),
49+
});
50+
await closeWithSuccess();
51+
52+
assertExecutedCommands(
53+
'log',
54+
`--pretty=format:${START_BOUNDARY}%H${COMMIT_BOUNDARY}`,
55+
'--follow',
56+
'--fixed-strings',
57+
'--',
58+
'index.js',
59+
'file2'
60+
);
61+
});
62+
63+
it('follow option works with pathspec workaround', async () => {
64+
git.log({
65+
'format': { hash: '%H' },
66+
'file': 'index.js',
67+
'--': null,
68+
});
69+
await closeWithSuccess();
70+
71+
assertExecutedCommands(
72+
'log',
73+
`--pretty=format:${START_BOUNDARY}%H${COMMIT_BOUNDARY}`,
3774
'--follow',
75+
'--',
3876
'index.js'
3977
);
4078
});
@@ -542,7 +580,7 @@ ${START_BOUNDARY}207601debebc170830f2921acf2b6b27034c3b1f::2016-01-03 15:50:58 +
542580
git.log({ file: '/foo/bar.txt', n: 10 });
543581
await closeWithSuccess();
544582

545-
assertCommandAppended('--max-count=10', '--follow', '/foo/bar.txt');
583+
assertCommandAppended('--max-count=10', '--follow', '--', '/foo/bar.txt');
546584
});
547585

548586
function assertCommandAppended(...things: string[]) {

0 commit comments

Comments
 (0)