@@ -120,26 +120,14 @@ impl ProjectContextData {
120120 Self :: load_root_dir ( & mut svc_ctxs_map, path. clone ( ) ) . await ;
121121
122122 // Compute the git diff between the current branch and the local changes
123- let mut cmd = Command :: new ( "git" ) ;
124- cmd. current_dir ( path) . arg ( "diff" ) . arg ( "--minimal" ) ;
125- source_diff. push_str (
126- & cmd. exec_string_with_err ( "Failed to get source hash" , true )
127- . await
128- . unwrap ( ) ,
129- ) ;
123+ source_diff. push_str ( & get_source_diff ( & path) . await . unwrap ( ) ) ;
130124 }
131125
132126 // Load main project after sub projects so it overrides sub project services
133127 Self :: load_root_dir ( & mut svc_ctxs_map, project_root. clone ( ) ) . await ;
134128
135129 // Compute the git diff between the current branch and the local changes
136- let mut cmd = Command :: new ( "git" ) ;
137- cmd. current_dir ( & project_root) . arg ( "diff" ) . arg ( "--minimal" ) ;
138- source_diff. push_str (
139- & cmd. exec_string_with_err ( "Failed to get source hash" , true )
140- . await
141- . unwrap ( ) ,
142- ) ;
130+ source_diff. push_str ( & get_source_diff ( & project_root) . await . unwrap ( ) ) ;
143131
144132 // If there is no diff, use the git commit hash
145133 let source_hash = if source_diff. is_empty ( ) {
@@ -1174,3 +1162,41 @@ impl ProjectContextData {
11741162 Ok ( value_str)
11751163 }
11761164}
1165+
1166+ async fn get_source_diff ( path : & Path ) -> Result < String > {
1167+ use tokio:: io:: AsyncReadExt ;
1168+ use tokio:: process:: Command ;
1169+
1170+ // Get git diff
1171+ let diff_output = Command :: new ( "git" )
1172+ . current_dir ( path)
1173+ . args ( & [ "--no-pager" , "diff" , "HEAD" , "--minimal" ] )
1174+ . output ( )
1175+ . await ?;
1176+ let mut result = String :: from_utf8 ( diff_output. stdout ) ?;
1177+
1178+ // Add diff for untracked files
1179+ let ls_files_output = Command :: new ( "git" )
1180+ . current_dir ( path)
1181+ . args ( & [
1182+ "--no-pager" ,
1183+ "ls-files" ,
1184+ "-z" ,
1185+ "--others" ,
1186+ "--exclude-standard" ,
1187+ ] )
1188+ . output ( )
1189+ . await ?;
1190+ for file in String :: from_utf8 ( ls_files_output. stdout ) ?. split ( '\0' ) {
1191+ if !file. is_empty ( ) {
1192+ let mut file_content = String :: new ( ) ;
1193+ tokio:: fs:: File :: open ( path. join ( file) )
1194+ . await ?
1195+ . read_to_string ( & mut file_content)
1196+ . await ?;
1197+ result. push_str ( & file_content) ;
1198+ }
1199+ }
1200+
1201+ Ok ( result)
1202+ }
0 commit comments