@@ -131,7 +131,7 @@ fn maybe_status_fastpath_internal(
131
131
132
132
let relativizer = PathRelativizer :: new ( cwd, repo_root) ;
133
133
let relativizer = HgStatusPathRelativizer :: new ( print_config. root_relative , relativizer) ;
134
- print_config. print_status (
134
+ let return_code = print_config. print_status (
135
135
& repo_root,
136
136
& status. status ,
137
137
& dirstate_data,
@@ -184,7 +184,7 @@ Your running Eden server is more than 45 days old. You should run
184
184
}
185
185
}
186
186
187
- Ok ( 0 )
187
+ Ok ( return_code )
188
188
}
189
189
190
190
const NULL_COMMIT : [ u8 ; 20 ] = [ 0 ; 20 ] ;
@@ -426,7 +426,7 @@ impl PrintConfig {
426
426
relativizer : & HgStatusPathRelativizer ,
427
427
use_color : bool ,
428
428
io : & mut IO ,
429
- ) -> Result < ( ) > {
429
+ ) -> Result < u8 > {
430
430
let groups = group_entries ( & repo_root, & status, & dirstate_data) ?;
431
431
let endl = self . endl ;
432
432
@@ -503,7 +503,21 @@ impl PrintConfig {
503
503
& groups. ignored ,
504
504
) ?;
505
505
print_group ( PrintGroup :: Clean , self . status_types . clean , & groups. clean ) ?;
506
- return Ok ( ( ) ) ;
506
+
507
+ if status. errors . is_empty ( ) {
508
+ Ok ( 0 )
509
+ } else {
510
+ io. write_err ( "Encountered errors computing status for some paths:\n " ) ?;
511
+ for ( path_str, error) in & status. errors {
512
+ let path = Path :: new ( str:: from_utf8 ( path_str) ?) ;
513
+ io. write_err ( format ! (
514
+ " {}: {}\n " ,
515
+ & relativizer. relativize( & path. to_path_buf( ) ) . display( ) ,
516
+ error,
517
+ ) ) ?;
518
+ }
519
+ Ok ( 1 )
520
+ }
507
521
}
508
522
}
509
523
@@ -802,11 +816,13 @@ mod test {
802
816
p1 : [ u8 ; 20 ] ,
803
817
p2 : [ u8 ; 20 ] ,
804
818
entries : BTreeMap < Vec < u8 > , ScmFileStatus > ,
819
+ errors : BTreeMap < Vec < u8 > , String > ,
805
820
dirstate_data_tuples : HashMap < PathBuf , DirstateDataTuple > ,
806
821
files : Vec < ( & ' a str , Fixture < ' a > ) > ,
807
822
use_color : bool ,
808
823
stdout : String ,
809
824
stderr : String ,
825
+ return_code : u8 ,
810
826
}
811
827
812
828
/// This function is used to drive most of the tests. It runs PrintConfig.print_status(), so it
@@ -831,7 +847,7 @@ mod test {
831
847
} ;
832
848
let status = ScmStatus {
833
849
entries : test_case. entries ,
834
- .. Default :: default ( )
850
+ errors : test_case . errors ,
835
851
} ;
836
852
837
853
let relativizer = HgStatusPathRelativizer :: new (
@@ -842,16 +858,16 @@ mod test {
842
858
let tout = Vec :: new ( ) ;
843
859
let terr = Vec :: new ( ) ;
844
860
let mut io = IO :: new ( tin, tout, Some ( terr) ) ;
845
- assert ! ( print_config
861
+ let return_code = print_config
846
862
. print_status (
847
863
repo_root. path ( ) ,
848
864
& status,
849
865
& dirstate_data,
850
866
& relativizer,
851
867
test_case. use_color ,
852
- & mut io
868
+ & mut io,
853
869
)
854
- . is_ok ( ) ) ;
870
+ . unwrap ( ) ;
855
871
let actual_output = io. output . as_any ( ) . downcast_ref :: < Vec < u8 > > ( ) . unwrap ( ) ;
856
872
assert_eq ! ( str :: from_utf8( actual_output) . unwrap( ) , test_case. stdout) ;
857
873
let actual_error = io
@@ -862,6 +878,7 @@ mod test {
862
878
. downcast_ref :: < Vec < u8 > > ( )
863
879
. unwrap ( ) ;
864
880
assert_eq ! ( str :: from_utf8( actual_error) . unwrap( ) , test_case. stderr) ;
881
+ assert_eq ! ( return_code, test_case. return_code) ;
865
882
}
866
883
867
884
fn one_modified_file ( ) -> BTreeMap < Vec < u8 > , ScmFileStatus > {
@@ -1087,4 +1104,38 @@ I ignored.txt
1087
1104
& p2
1088
1105
) ) ;
1089
1106
}
1107
+
1108
+ #[ test]
1109
+ fn status_with_errors ( ) {
1110
+ let mut entries = BTreeMap :: new ( ) ;
1111
+ entries. insert ( "unknown.txt" . into ( ) , ScmFileStatus :: ADDED ) ;
1112
+ entries. insert ( "modified.txt" . into ( ) , ScmFileStatus :: MODIFIED ) ;
1113
+
1114
+ let mut errors = BTreeMap :: new ( ) ;
1115
+ errors. insert (
1116
+ "src/lib" . into ( ) ,
1117
+ "unable to fetch directory data: connection reset" . into ( ) ,
1118
+ ) ;
1119
+
1120
+ let color_stdout = concat ! (
1121
+ "\u{001B} [34m\u{001B} [1mM modified.txt\u{001B} [0m\n " ,
1122
+ "\u{001B} [35m\u{001B} [1m\u{001b} [4m? unknown.txt\u{001B} [0m\n " ,
1123
+ ) ;
1124
+ let src_lib_path = Path :: new ( "src" ) . join ( "lib" ) ;
1125
+ let stderr = format ! (
1126
+ "{}\n {}: {}\n " ,
1127
+ "Encountered errors computing status for some paths:" ,
1128
+ src_lib_path. display( ) ,
1129
+ "unable to fetch directory data: connection reset" ,
1130
+ ) ;
1131
+ test_status ( StatusTestCase {
1132
+ entries,
1133
+ errors,
1134
+ use_color : true ,
1135
+ stdout : color_stdout. to_string ( ) ,
1136
+ stderr : stderr. to_string ( ) ,
1137
+ return_code : 1 ,
1138
+ ..Default :: default ( )
1139
+ } ) ;
1140
+ }
1090
1141
}
0 commit comments