Skip to content

Commit 2eda817

Browse files
committed
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
1 parent d64b31c commit 2eda817

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
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

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',
37+
'--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',
3656
'--fixed-strings',
57+
'--',
58+
'file2',
59+
'index.js'
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)