Git fork

diff: accept -- when using --no-index

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.

While at it, fix the parsing of "-q" option in --no-index mode as well.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Thomas Rast and committed by
Junio C Hamano
e423ffd8 a567fdcb

+11 -3
+7 -3
diff-no-index.c
··· 173 174 /* Were we asked to do --no-index explicitly? */ 175 for (i = 1; i < argc; i++) { 176 - if (!strcmp(argv[i], "--")) 177 - return; 178 if (!strcmp(argv[i], "--no-index")) 179 no_index = 1; 180 if (argv[i][0] != '-') ··· 212 int j; 213 if (!strcmp(argv[i], "--no-index")) 214 i++; 215 - else if (!strcmp(argv[1], "-q")) 216 options |= DIFF_SILENT_ON_REMOVED; 217 else { 218 j = diff_opt_parse(&revs->diffopt, argv + i, argc - i); 219 if (!j)
··· 173 174 /* Were we asked to do --no-index explicitly? */ 175 for (i = 1; i < argc; i++) { 176 + if (!strcmp(argv[i], "--")) { 177 + i++; 178 + break; 179 + } 180 if (!strcmp(argv[i], "--no-index")) 181 no_index = 1; 182 if (argv[i][0] != '-') ··· 214 int j; 215 if (!strcmp(argv[i], "--no-index")) 216 i++; 217 + else if (!strcmp(argv[i], "-q")) 218 options |= DIFF_SILENT_ON_REMOVED; 219 + else if (!strcmp(argv[i], "--")) 220 + i++; 221 else { 222 j = diff_opt_parse(&revs->diffopt, argv + i, argc - i); 223 if (!j)
+1
t/t4013-diff-various.sh
··· 261 diff --patch-with-raw -r initial..side 262 diff --name-status dir2 dir 263 diff --no-index --name-status dir2 dir 264 diff master master^ side 265 EOF 266
··· 261 diff --patch-with-raw -r initial..side 262 diff --name-status dir2 dir 263 diff --no-index --name-status dir2 dir 264 + diff --no-index --name-status -- dir2 dir 265 diff master master^ side 266 EOF 267
+3
t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir
···
··· 1 + $ git diff --no-index --name-status -- dir2 dir 2 + A dir/sub 3 + $