git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] shortlog: do not require to run from inside a git repository
@ 2008-03-14 21:35 Jonas Fonseca
  2008-03-16  3:55 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Jonas Fonseca @ 2008-03-14 21:35 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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>
---
 builtin-shortlog.c  |    4 +++-
 git.c               |    2 +-
 t/t4201-shortlog.sh |    5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)

 On top of next.

diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index b22b0ed..bd795b1 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -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 */
@@ -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);
diff --git a/git.c b/git.c
index 1e3eb10..13de801 100644
--- a/git.c
+++ b/git.c
@@ -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 },
diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
index 91ea696..405b971 100755
--- a/t/t4201-shortlog.sh
+++ b/t/t4201-shortlog.sh
@@ -47,4 +47,9 @@ EOF
 
 test_expect_success 'shortlog wrapping' 'test_cmp expect out'
 
+git log HEAD > log
+GIT_DIR=non-existing git shortlog -w < log > out
+
+test_expect_success 'shortlog from non-git directory' 'test_cmp expect out'
+
 test_done
-- 
1.5.4.4.684.g0e08.dirty

-- 
Jonas Fonseca

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] shortlog: do not require to run from inside a git repository
  2008-03-14 21:35 [PATCH] shortlog: do not require to run from inside a git repository Jonas Fonseca
@ 2008-03-16  3:55 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-03-16  3:55 UTC (permalink / raw)
  To: Jonas Fonseca; +Cc: git

Jonas Fonseca <fonseca@diku.dk> writes:

> 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.

Nice regression fix.  Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-03-16  3:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-14 21:35 [PATCH] shortlog: do not require to run from inside a git repository Jonas Fonseca
2008-03-16  3:55 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).