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