From 95b9f9f927a7d9ea2bc2849b6ae624335e98362f Mon Sep 17 00:00:00 2001
From: Brandon Casey <drafnel@gmail.com>
Date: Thu, 26 May 2011 13:43:20 -0700
Subject: [PATCH 1/2] t7508: demonstrate status's failure to use --porcelain
 format with -z

When 'git status' is supplied the -z switch, and no output format has been
selected, it is supposed to use the --porcelain format.  This does not
happen.  Instead, the standard long format is used.  Add a test to
demonstrate this failure.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t7508-status.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 1173dbb36e7..9bc9817f289 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -364,6 +364,13 @@ test_expect_success 'status submodule summary (clean submodule)' '
 	test_cmp expect output
 '
 
+test_expect_failure 'status -z implies porcelain' '
+	git status --porcelain |
+	perl -pe "s/\012/\000/g" >expect &&
+	git status -z >output &&
+	test_cmp expect output
+'
+
 cat >expect <<EOF
 # On branch master
 # Changes to be committed:

From 000f97bd11e94fa8ede7fcdb43f5633997fed672 Mon Sep 17 00:00:00 2001
From: Brandon Casey <drafnel@gmail.com>
Date: Thu, 26 May 2011 13:43:21 -0700
Subject: [PATCH 2/2] builtin/commit.c: set status_format _after_ option
 parsing

'git status' should use --porcelain output format when -z is given.
It was not doing so since the _effect_ of using -z, namely that
null_termination would be set, was being checked _before_ option parsing
was performed.

So, move the check so that it is performed after option parsing.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-commit.c  | 7 ++++---
 t/t7508-status.sh | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index f2fd0a45808..9e7208f729d 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -1039,14 +1039,15 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		OPT_END(),
 	};
 
-	if (null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
-
 	wt_status_prepare(&s);
 	git_config(git_status_config, &s);
 	argc = parse_options(argc, argv, prefix,
 			     builtin_status_options,
 			     builtin_status_usage, 0);
+
+	if (null_termination && status_format == STATUS_FORMAT_LONG)
+		status_format = STATUS_FORMAT_PORCELAIN;
+
 	handle_untracked_files_arg(&s);
 
 	if (*argv)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 9bc9817f289..d4844abf13c 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -364,7 +364,7 @@ test_expect_success 'status submodule summary (clean submodule)' '
 	test_cmp expect output
 '
 
-test_expect_failure 'status -z implies porcelain' '
+test_expect_success 'status -z implies porcelain' '
 	git status --porcelain |
 	perl -pe "s/\012/\000/g" >expect &&
 	git status -z >output &&