Skip to content

Commit e423ffd

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a567fdc commit e423ffd

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

diff-no-index.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ void diff_no_index(struct rev_info *revs,
173173

174174
/* Were we asked to do --no-index explicitly? */
175175
for (i = 1; i < argc; i++) {
176-
if (!strcmp(argv[i], "--"))
177-
return;
176+
if (!strcmp(argv[i], "--")) {
177+
i++;
178+
break;
179+
}
178180
if (!strcmp(argv[i], "--no-index"))
179181
no_index = 1;
180182
if (argv[i][0] != '-')
@@ -212,8 +214,10 @@ void diff_no_index(struct rev_info *revs,
212214
int j;
213215
if (!strcmp(argv[i], "--no-index"))
214216
i++;
215-
else if (!strcmp(argv[1], "-q"))
217+
else if (!strcmp(argv[i], "-q"))
216218
options |= DIFF_SILENT_ON_REMOVED;
219+
else if (!strcmp(argv[i], "--"))
220+
i++;
217221
else {
218222
j = diff_opt_parse(&revs->diffopt, argv + i, argc - i);
219223
if (!j)

t/t4013-diff-various.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ diff --patch-with-stat -r initial..side
261261
diff --patch-with-raw -r initial..side
262262
diff --name-status dir2 dir
263263
diff --no-index --name-status dir2 dir
264+
diff --no-index --name-status -- dir2 dir
264265
diff master master^ side
265266
EOF
266267

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$ git diff --no-index --name-status -- dir2 dir
2+
A dir/sub
3+
$

0 commit comments

Comments
 (0)