@matheusbsbs / matheus-bagliano / commits / e423ffd8a6
Fork 0

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>

Thomas Rast committed Jan 6, 2009 at 19:53 UTC e423ffd8a6f46a14ecbb637d909290bd3579cebd
3 files changed +11 -3
diff-no-index.c
+7 -3
@@ -173,8 +173,10 @@ void diff_no_index(struct rev_info *revs,
173
174 /* Were we asked to do --no-index explicitly? */
175 for (i = 1; i < argc; i++) {
176 - if (!strcmp(argv[i], "--"))
177 - return;
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] != '-')
@@ -212,8 +214,10 @@ void diff_no_index(struct rev_info *revs,
214 int j;
215 if (!strcmp(argv[i], "--no-index"))
216 i++;
215 - else if (!strcmp(argv[1], "-q"))
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)
t/t4013-diff-various.sh
+1
@@ -261,6 +261,7 @@ diff --patch-with-stat -r initial..side
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
t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir new
+3
@@ -0,0 +1,3 @@
1 +$ git diff --no-index --name-status -- dir2 dir
2 +A dir/sub
3 +$