Skip to content

Commit

Permalink
shortlog: do not require to run from inside a git repository
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jonas Fonseca authored and Junio C Hamano committed Mar 15, 2008
1 parent 267123b commit abe549e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion builtin-shortlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
{
struct shortlog log;
struct rev_info rev;
int nongit;

prefix = setup_git_directory_gently(&nongit);
shortlog_init(&log);

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

/* assume HEAD if from a tty */
if (!rev.pending.nr && isatty(0))
if (!nongit && !rev.pending.nr && isatty(0))
add_head_to_pending(&rev);
if (rev.pending.nr == 0) {
read_from_stdin(&log);
Expand Down
2 changes: 1 addition & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
{ "rm", cmd_rm, RUN_SETUP },
{ "send-pack", cmd_send_pack, RUN_SETUP },
{ "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },
{ "shortlog", cmd_shortlog, USE_PAGER },
{ "show-branch", cmd_show_branch, RUN_SETUP },
{ "show", cmd_show, RUN_SETUP | USE_PAGER },
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
Expand Down
5 changes: 5 additions & 0 deletions t/t4201-shortlog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ EOF

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

git log HEAD > log
GIT_DIR=non-existing git shortlog -w < log > out

test_expect_success 'shortlog from non-git directory' 'diff -u expect out'

test_done

0 comments on commit abe549e

Please sign in to comment.