@@ -7,7 +7,10 @@ use rustc_hash::FxHashSet;
77use serde:: { Deserialize , Serialize } ;
88use starbase_styles:: color;
99use starbase_utils:: json;
10- use std:: io:: { IsTerminal , Read , stdin} ;
10+ use std:: io:: { IsTerminal , stdin} ;
11+ use std:: time:: Duration ;
12+ use tokio:: io:: AsyncReadExt ;
13+ use tokio:: time:: timeout;
1114use tracing:: { debug, trace, warn} ;
1215
1316#[ derive( Clone , Default , Deserialize , Serialize ) ]
@@ -54,8 +57,6 @@ pub async fn query_touched_files(
5457 vcs : & BoxedVcs ,
5558 options : & QueryTouchedFilesOptions ,
5659) -> miette:: Result < QueryTouchedFilesResult > {
57- debug ! ( "Querying for touched files" ) ;
58-
5960 let bag = GlobalEnvBag :: instance ( ) ;
6061 let default_branch = vcs. get_default_branch ( ) . await ?;
6162 let current_branch = vcs. get_local_branch ( ) . await ?;
@@ -157,24 +158,37 @@ pub async fn query_touched_files_with_stdin(
157158 vcs : & BoxedVcs ,
158159 options : & QueryTouchedFilesOptions ,
159160) -> miette:: Result < QueryTouchedFilesResult > {
161+ debug ! ( "Querying for touched files" ) ;
162+
160163 let mut buffer = String :: new ( ) ;
161164
162165 // Only read piped data when stdin is not a TTY,
163166 // otherwise the process will hang indefinitely waiting for EOF.
164167 if !stdin ( ) . is_terminal ( ) {
165- stdin ( ) . read_to_string ( & mut buffer) . into_diagnostic ( ) ?;
168+ if let Ok ( read_result) = timeout (
169+ Duration :: from_secs ( 10 ) ,
170+ tokio:: io:: stdin ( ) . read_to_string ( & mut buffer) ,
171+ )
172+ . await
173+ {
174+ read_result. into_diagnostic ( ) ?;
175+ }
166176 }
167177
168178 // If piped via stdin, parse and use it
169179 if !buffer. is_empty ( ) {
170180 // As JSON
171181 if buffer. starts_with ( '{' ) {
182+ debug ! ( "Received from stdin as JSON" ) ;
183+
172184 let result: QueryTouchedFilesResult = json:: parse ( & buffer) ?;
173185
174186 return Ok ( result) ;
175187 }
176188 // As lines
177189 else {
190+ debug ! ( "Received from stdin as separate lines" ) ;
191+
178192 let files =
179193 FxHashSet :: from_iter ( buffer. split ( '\n' ) . map ( WorkspaceRelativePathBuf :: from) ) ;
180194
0 commit comments