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

[PATCH] diff: accept -- when using --no-index

From
Thomas Rast <trast@student.ethz.ch>
Date
Jan 6, 2009, 18:53 UTC
Message-ID
<1231268012-5592-1-git-send-email-trast@student.ethz.ch>

Accept -- as an "end of options" marker even when using --no-index. Previously, the -- triggered a "normal" index/tree diff and subsequently failed because of the unrecognized (in that mode) --no-index.

Note that the second loop can treat '--' as a normal option, because the preceding checks ensure it is the third-to-last argument.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 diff-no-index.c                                    |    8 ++++++--
 t/t4013-diff-various.sh                            |    1 +
 .../diff.diff_--no-index_--name-status_--_dir2_dir |    3 +++
 3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index b60d345..d1e8e4b 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -173,8 +173,10 @@ void diff_no_index(struct rev_info *revs,
 
 	/* Were we asked to do --no-index explicitly? */
 	for (i = 1; i < argc; i++) {
-		if (!strcmp(argv[i], "--"))
-			return;
+		if (!strcmp(argv[i], "--")) {
+			i++;
+			break;
+		}
 		if (!strcmp(argv[i], "--no-index"))
 			no_index = 1;
 		if (argv[i][0] != '-')
@@ -214,6 +216,8 @@ void diff_no_index(struct rev_info *revs,
 			i++;
 		else if (!strcmp(argv[1], "-q"))
 			options |= DIFF_SILENT_ON_REMOVED;
+		else if (!strcmp(argv[i], "--"))
+			i++;
 		else {
 			j = diff_opt_parse(&revs->diffopt, argv + i, argc - i);
 			if (!j)
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index aeb5405..aba5320 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -261,6 +261,7 @@ diff --patch-with-stat -r initial..side
 diff --patch-with-raw -r initial..side
 diff --name-status dir2 dir
 diff --no-index --name-status dir2 dir
+diff --no-index --name-status -- dir2 dir
 diff master master^ side
 EOF
 
diff --git a/t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir b/t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir
new file mode 100644
index 0000000..6756f8d
--- /dev/null
+++ b/t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir
@@ -0,0 +1,3 @@
+$ git diff --no-index --name-status -- dir2 dir
+A	dir/sub
+$
-- 
tg: (e9b8523..) t/diff-no-index-invocation (depends on: origin/master)
Message 1 of 1 in “diff: accept -- when using --no-index”
  1. diff: accept -- when using --no-indexThomas Rast, Jan 6, 2009

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.