git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] builtin/commit.c: set status_format _after_ option parsing

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
May 26, 2011, 20:43 UTC
Message-ID
<vdMu20HxiNaWL_IogfamtflLupHrDNZVtQH5MK7obj8IjaOAuDtj-EwLzysKLoeGXYfBRtJqF-hgEQF5bfRzsQ@cipher.nrlssc.navy.mil>
In-Reply-To
<vdMu20HxiNaWL_IogfamtfZCd6xRyKanIqTSw0k4f2SrbLfUYHDzKT2EGkwdFRlaLzX-5vGGtDCZRGu84HrJzw@cipher.nrlssc.navy.mil>
From: Brandon Casey <drafnel@gmail.com>

'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>
---
 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 5286432..e1af9b1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1207,9 +1207,6 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage_with_options(builtin_status_usage, builtin_status_options);
 
-	if (null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
-
 	wt_status_prepare(&s);
 	gitmodules_config();
 	git_config(git_status_config, &s);
@@ -1217,6 +1214,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	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 (show_ignored_in_status)
 		s.show_ignored_files = 1;
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 9601258..dc2cc33 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -533,7 +533,7 @@ test_expect_success 'status --porcelain ignores -b' '
 
 '
 
-test_expect_failure 'status -z implies porcelain' '
+test_expect_success 'status -z implies porcelain' '
 	echo " M dir1/modifiedQA  dir2/addedQ?? dir1/untrackedQ?? dir2/modifiedQ?? dir2/untrackedQ?? expectQ?? outputQ?? untrackedQ" |
 		q_to_nul | tr -d "\\012" >expect &&
 	git status -z >output &&
-- 
1.7.4.4
Previous: Brandon CaseyNext: Jeff King
Message 2 of 7 in “t7508: demonstrate status's failure to use --porcelain format with -z”
  1. 1/2 t7508: demonstrate status's failure to use --porcelain format with -zBrandon Casey, May 26, 2011
  2. 2/2 builtin/commit.c: set status_format _after_ option parsingBrandon Casey, May 26, 2011
  3. Jeff KingMay 26, 2011
  4. Brandon CaseyMay 26, 2011
  5. Junio C HamanoMay 26, 2011
  6. Brandon CaseyMay 26, 2011
  7. Junio C HamanoMay 26, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.