Skip to content

Commit

Permalink
Use pathspec in git.log task to allow for the use of previously d…
Browse files Browse the repository at this point in the history
…eleted 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
  • Loading branch information
steveukx committed Sep 23, 2023
1 parent d64b31c commit 2eda817
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 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
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',
'--',
'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'
);
});
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 2eda817

Please sign in to comment.