@@ -304,13 +304,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
304304
305305 DIFF_OPT_SET (& rev .diffopt , RECURSIVE );
306306
307- /*
308- * If the user asked for our exit code then don't start a
309- * pager or we would end up reporting its exit code instead.
310- */
311- if (!DIFF_OPT_TST (& rev .diffopt , EXIT_WITH_STATUS ) &&
312- check_pager_config ("diff" ) != 0 )
313- setup_pager ();
307+ setup_diff_pager (& rev .diffopt );
314308
315309 /*
316310 * Do we have --cached and not have a pending object, then
@@ -421,3 +415,19 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
421415 refresh_index_quietly ();
422416 return result ;
423417}
418+
419+ void setup_diff_pager (struct diff_options * opt )
420+ {
421+ /*
422+ * If the user asked for our exit code, then either they want --quiet
423+ * or --exit-code. We should definitely not bother with a pager in the
424+ * former case, as we will generate no output. Since we still properly
425+ * report our exit code even when a pager is run, we _could_ run a
426+ * pager with --exit-code. But since we have not done so historically,
427+ * and because it is easy to find people oneline advising "git diff
428+ * --exit-code" in hooks and other scripts, we do not do so.
429+ */
430+ if (!DIFF_OPT_TST (opt , EXIT_WITH_STATUS ) &&
431+ check_pager_config ("diff" ) != 0 )
432+ setup_pager ();
433+ }
0 commit comments