@@ -875,3 +875,73 @@ fn a_known_repo_spelled_otherwise_becomes_the_spelling_wsl_resolves(cx: &mut Tes
875875 } ) ;
876876 assert_eq ! ( reviews. read_with( cx, |reviews, _| reviews. rows( ) . len( ) ) , 1 ) ;
877877}
878+
879+ #[ gpui:: test]
880+ async fn a_removed_repo_leaves_the_list_and_the_file_keeping_its_reviews ( cx : & mut TestAppContext ) {
881+ let data = tempfile:: tempdir ( ) . unwrap ( ) ;
882+ let repo = fixture ( ) ;
883+ let other = fixture ( ) ;
884+ let ( locations, reviews) = services ( cx, data. path ( ) ) ;
885+ locations. update ( cx, |locations, _| {
886+ locations. register_env ( repo. path ( ) . to_path_buf ( ) , repo. env_overlay ( ) ) ;
887+ locations. register_env ( other. path ( ) . to_path_buf ( ) , other. env_overlay ( ) ) ;
888+ } ) ;
889+ let location = Location :: Local ( repo. path ( ) . to_path_buf ( ) ) ;
890+ let kept = Location :: Local ( other. path ( ) . to_path_buf ( ) ) ;
891+ for added in [ & location, & kept] {
892+ reviews
893+ . update ( cx, |reviews, cx| reviews. add_repo ( added. clone ( ) , cx) )
894+ . await
895+ . expect ( "a repo" ) ;
896+ }
897+ let opened = reviews
898+ . update ( cx, |reviews, cx| {
899+ reviews. open_review ( location. clone ( ) , Target :: Working , cx)
900+ } )
901+ . await
902+ . expect ( "a review" ) ;
903+ settle ( cx, & reviews) ;
904+
905+ // Removed while a refresh of it runs: the row goes at once, and the refresh lands nowhere.
906+ let removed = reviews. update ( cx, |reviews, cx| {
907+ reviews. refresh ( location. clone ( ) , cx) ;
908+ reviews. remove_repo ( & location, cx)
909+ } ) ;
910+ assert ! ( removed) ;
911+ settle ( cx, & reviews) ;
912+ reviews. read_with ( cx, |reviews, _| {
913+ assert ! ( reviews. row( & location) . is_none( ) ) ;
914+ assert ! ( reviews. known( ) . get( & location) . is_none( ) ) ;
915+ assert_eq ! ( reviews. rows( ) . len( ) , 1 ) ;
916+ assert_eq ! ( reviews. rows( ) [ 0 ] . location, kept) ;
917+ } ) ;
918+ let saved: Value =
919+ serde_json:: from_str ( & std:: fs:: read_to_string ( data. path ( ) . join ( KNOWN_REPOS_FILE ) ) . unwrap ( ) )
920+ . unwrap ( ) ;
921+ assert_eq ! (
922+ saved[ "repos" ] . as_array( ) . unwrap( ) . len( ) ,
923+ 1 ,
924+ "saved without it"
925+ ) ;
926+ assert_eq ! (
927+ saved[ "repos" ] [ 0 ] [ "location" ] ,
928+ serde_json:: to_value( & kept) . unwrap( )
929+ ) ;
930+ // Not known any more, so nothing to remove.
931+ assert ! ( !reviews. update( cx, |reviews, cx| reviews. remove_repo( & location, cx) ) ) ;
932+
933+ // Added again, it lists its review: nothing in the repository was touched.
934+ reviews
935+ . update ( cx, |reviews, cx| reviews. add_repo ( location. clone ( ) , cx) )
936+ . await
937+ . expect ( "added again" ) ;
938+ settle ( cx, & reviews) ;
939+ reviews. read_with ( cx, |reviews, _| {
940+ let row = reviews. row ( & location) . expect ( "listed again" ) ;
941+ assert_eq ! (
942+ row. open_review_of( & Target :: Working )
943+ . map( |summary| & summary. id) ,
944+ Some ( & opened. loaded. review. id)
945+ ) ;
946+ } ) ;
947+ }
0 commit comments