Skip to content

Commit d0dceda

Browse files
authored
Allow using just one of from and to in the git.log options. (#846)
* Allow using just one of `from` and `to` in the `git.log` options. Closes #845
1 parent 6b3e05c commit d0dceda

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

.changeset/spotty-needles-leave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'simple-git': minor
3+
---
4+
5+
Allow supplying just one of to/from in the options supplied to git.log

simple-git/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,14 @@ For type details of the response for each of the tasks, please see the [TypeScri
295295

296296
- `options.file` - the path to a file in your repository to only consider this path.
297297
- `options.format` - custom log format object, keys are the property names used on the returned object, values are the format string from [pretty formats](https://git-scm.com/docs/pretty-formats#Documentation/pretty-formats.txt)
298-
- `options.from` - when supplied along with `options.to` sets the range of commits to log
298+
- `options.from` - sets the oldest commit in the range to return, use along with `options.to` to set a bounded range
299299
- `options.mailMap` - defaults to true, enables the use of [mail map](https://git-scm.com/docs/gitmailmap) in returned values for email and name from the default format
300300
- `options.maxCount` - equivalent to setting the `--max-count` option
301301
- `options.multiLine` - enables multiline body values in the default format (disabled by default)
302302
- `options.splitter` - the character sequence to use as a delimiter between fields in the log, should be a value that doesn't appear in any log message (defaults to `ò`)
303303
- `options.strictDate` - switches the authored date value from an ISO 8601-like format to be strict ISO 8601 format
304304
- `options.symmetric` - defaults to true, enables [symmetric revision range](https://git-scm.com/docs/gitrevisions#_dotted_range_notations) rather than a two-dot range
305-
- `options.to` - when supplied along with `options.from` sets the range of commits to log
305+
- `options.to` - sets the newset commit in the range to return, use along with `options.from` to set a bounded range
306306

307307
## git merge
308308

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ export function parseLogOptions<T extends Options>(
120120
command.push(`--max-count=${maxCount}`);
121121
}
122122

123-
if (opt.from && opt.to) {
123+
if (opt.from || opt.to) {
124124
const rangeOperator = opt.symmetric !== false ? '...' : '..';
125-
suffix.push(`${opt.from}${rangeOperator}${opt.to}`);
125+
suffix.push(`${opt.from || ''}${rangeOperator}${opt.to || ''}`);
126126
}
127127

128128
if (filterString(opt.file)) {

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

+16
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,22 @@ ${START_BOUNDARY}207601debebc170830f2921acf2b6b27034c3b1f::2016-01-03 15:50:58 +
568568
assertExecutedCommandsContains('--all');
569569
});
570570

571+
it.each([
572+
[{ from: 'from' }, 'from...'],
573+
[{ to: 'to' }, '...to'],
574+
[{ from: 'from', to: '' }, 'from...'],
575+
[{ from: '', to: 'to' }, '...to'],
576+
[{ from: 'from', symmetric: true }, 'from...'],
577+
[{ to: 'to', symmetric: true }, '...to'],
578+
[{ from: 'from', symmetric: false }, 'from..'],
579+
[{ to: 'to', symmetric: false }, '..to'],
580+
])(`supports partial with options %s`, async (options, result) => {
581+
git.log(options);
582+
583+
await closeWithSuccess();
584+
assertExecutedCommandsContains(result);
585+
});
586+
571587
it('when awaiting options object', async () => {
572588
const from = 'from-name';
573589
const to = 'to-name';

0 commit comments

Comments
 (0)