Skip to content

Commit f630171

Browse files
committed
Merge branch 'tr/maint-no-index-fixes' into maint
* tr/maint-no-index-fixes: diff --no-index -q: fix endless loop diff --no-index: test for pager after option parsing diff: accept -- when using --no-index
2 parents 46cdcc6 + a324fc4 commit f630171

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

diff-no-index.c

Lines changed: 16 additions & 10 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] != '-')
@@ -198,22 +200,19 @@ void diff_no_index(struct rev_info *revs,
198200
die("git diff %s takes two paths",
199201
no_index ? "--no-index" : "[--no-index]");
200202

201-
/*
202-
* If the user asked for our exit code then don't start a
203-
* pager or we would end up reporting its exit code instead.
204-
*/
205-
if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS))
206-
setup_pager();
207-
208203
diff_setup(&revs->diffopt);
209204
if (!revs->diffopt.output_format)
210205
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
211206
for (i = 1; i < argc - 2; ) {
212207
int j;
213208
if (!strcmp(argv[i], "--no-index"))
214209
i++;
215-
else if (!strcmp(argv[1], "-q"))
210+
else if (!strcmp(argv[i], "-q")) {
216211
options |= DIFF_SILENT_ON_REMOVED;
212+
i++;
213+
}
214+
else if (!strcmp(argv[i], "--"))
215+
i++;
217216
else {
218217
j = diff_opt_parse(&revs->diffopt, argv + i, argc - i);
219218
if (!j)
@@ -222,6 +221,13 @@ void diff_no_index(struct rev_info *revs,
222221
}
223222
}
224223

224+
/*
225+
* If the user asked for our exit code then don't start a
226+
* pager or we would end up reporting its exit code instead.
227+
*/
228+
if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS))
229+
setup_pager();
230+
225231
if (prefix) {
226232
int len = strlen(prefix);
227233

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)