Skip to content

Commit abe549e

Browse files
jonasgitster
authored andcommitted
shortlog: do not require to run from inside a git repository
Once upon a time shortlog could be run from a non-git directory and still do its job. Fix this regression and add a small test for it. Signed-off-by: Jonas Fonseca <fonseca@diku.dk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 267123b commit abe549e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

builtin-shortlog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
229229
{
230230
struct shortlog log;
231231
struct rev_info rev;
232+
int nongit;
232233

234+
prefix = setup_git_directory_gently(&nongit);
233235
shortlog_init(&log);
234236

235237
/* since -n is a shadowed rev argument, parse our args first */
@@ -259,7 +261,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
259261
die ("unrecognized argument: %s", argv[1]);
260262

261263
/* assume HEAD if from a tty */
262-
if (!rev.pending.nr && isatty(0))
264+
if (!nongit && !rev.pending.nr && isatty(0))
263265
add_head_to_pending(&rev);
264266
if (rev.pending.nr == 0) {
265267
read_from_stdin(&log);

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static void handle_internal_command(int argc, const char **argv)
343343
{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
344344
{ "rm", cmd_rm, RUN_SETUP },
345345
{ "send-pack", cmd_send_pack, RUN_SETUP },
346-
{ "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },
346+
{ "shortlog", cmd_shortlog, USE_PAGER },
347347
{ "show-branch", cmd_show_branch, RUN_SETUP },
348348
{ "show", cmd_show, RUN_SETUP | USE_PAGER },
349349
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },

t/t4201-shortlog.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ EOF
4747

4848
test_expect_success 'shortlog wrapping' 'diff -u expect out'
4949

50+
git log HEAD > log
51+
GIT_DIR=non-existing git shortlog -w < log > out
52+
53+
test_expect_success 'shortlog from non-git directory' 'diff -u expect out'
54+
5055
test_done

0 commit comments

Comments
 (0)