Skip to content

Commit 7f7d712

Browse files
dschogitster
authored andcommitted
shortlog: respect the --output=<file> setting
Thanks to the diff option parsing, we already know about this option. We just have to make use of it. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 36a4d90 commit 7f7d712

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

builtin/shortlog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ void shortlog_init(struct shortlog *log)
229229
log->wrap = DEFAULT_WRAPLEN;
230230
log->in1 = DEFAULT_INDENT1;
231231
log->in2 = DEFAULT_INDENT2;
232-
log->file = stdout;
233232
}
234233

235234
int cmd_shortlog(int argc, const char **argv, const char *prefix)
@@ -277,6 +276,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
277276

278277
log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
279278
log.abbrev = rev.abbrev;
279+
log.file = rev.diffopt.file;
280280

281281
/* assume HEAD if from a tty */
282282
if (!nongit && !rev.pending.nr && isatty(0))
@@ -290,6 +290,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
290290
get_from_rev(&rev, &log);
291291

292292
shortlog_output(&log);
293+
if (log.file != stdout)
294+
fclose(log.file);
293295
return 0;
294296
}
295297

t/t4201-shortlog.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,10 @@ test_expect_success 'shortlog with revision pseudo options' '
184184
git shortlog --exclude=refs/heads/m* --all
185185
'
186186

187+
test_expect_success 'shortlog with --output=<file>' '
188+
git shortlog --output=shortlog master >output &&
189+
test ! -s output &&
190+
test_line_count = 7 shortlog
191+
'
192+
187193
test_done

0 commit comments

Comments
 (0)