@@ -2358,6 +2358,7 @@ impl<'test> TestCx<'test> {
23582358 let suffix =
23592359 self . safe_revision ( ) . map_or ( "nightly" . into ( ) , |path| path. to_owned ( ) + "-nightly" ) ;
23602360 let compare_dir = output_base_dir ( self . config , self . testpaths , Some ( & suffix) ) ;
2361+ // Don't give an error if the directory didn't already exist
23612362 let _ = fs:: remove_dir_all ( & compare_dir) ;
23622363 create_dir_all ( & compare_dir) . unwrap ( ) ;
23632364
@@ -2406,18 +2407,28 @@ impl<'test> TestCx<'test> {
24062407 self . fatal ( "failed to run tidy" ) ;
24072408 }
24082409
2409- let has_delta = Command :: new ( "delta" )
2410- . arg ( "--version" )
2411- . stdout ( Stdio :: null ( ) )
2412- . status ( )
2413- . map_or ( false , |status| status. success ( ) ) ;
2410+ let pager = {
2411+ let output = Command :: new ( "git" ) . args ( & [ "config" , "--get" , "core.pager" ] ) . output ( ) . ok ( ) ;
2412+ output. and_then ( |out| {
2413+ if out. status . success ( ) {
2414+ Some ( String :: from_utf8 ( out. stdout ) . expect ( "invalid UTF8 in git pager" ) )
2415+ } else {
2416+ None
2417+ }
2418+ } )
2419+ } ;
24142420 let mut diff = Command :: new ( "diff" ) ;
24152421 diff. args ( & [ "-u" , "-r" ] ) . args ( & [ out_dir, & compare_dir] ) ;
24162422
2417- let output = if has_delta {
2423+ let output = if let Some ( pager ) = pager {
24182424 let diff_pid = diff. stdout ( Stdio :: piped ( ) ) . spawn ( ) . expect ( "failed to run `diff`" ) ;
2419- let output = Command :: new ( "delta" )
2420- . arg ( "--paging=never" )
2425+ let pager = pager. trim ( ) ;
2426+ if self . config . verbose {
2427+ eprintln ! ( "using pager {}" , pager) ;
2428+ }
2429+ let output = Command :: new ( pager)
2430+ // disable paging; we want this to be non-interactive
2431+ . env ( "PAGER" , "" )
24212432 . stdin ( diff_pid. stdout . unwrap ( ) )
24222433 // Capture output and print it explicitly so it will in turn be
24232434 // captured by libtest.
@@ -2426,7 +2437,10 @@ impl<'test> TestCx<'test> {
24262437 assert ! ( output. status. success( ) ) ;
24272438 output
24282439 } else {
2429- eprintln ! ( "warning: `delta` not installed, falling back to `diff --color`" ) ;
2440+ eprintln ! ( "warning: no pager configured, falling back to `diff --color`" ) ;
2441+ eprintln ! (
2442+ "help: try configuring a git pager (e.g. `delta`) with `git config --global core.pager delta`"
2443+ ) ;
24302444 let output = diff. arg ( "--color" ) . output ( ) . unwrap ( ) ;
24312445 assert ! ( output. status. success( ) || output. status. code( ) == Some ( 1 ) ) ;
24322446 output
0 commit comments