@@ -263,6 +263,60 @@ fn test_revspec_starting_with_dash_rejected() {
263263 ) ;
264264}
265265
266+ #[ test]
267+ fn test_head_tilde_1_on_single_commit_repo_wraps_error ( ) {
268+ // Reproduces the CI failure: a shallow checkout has no parent for HEAD,
269+ // so revparse_single("HEAD~1") returns a libgit2 error whose raw message
270+ // ("parent 0 does not exist") contains neither "revspec" nor "not found".
271+ // The production wrapper must add that context so callers get a meaningful
272+ // error.
273+ let temp_dir = tempfile:: tempdir ( ) . expect ( "failed to create temp dir" ) ;
274+ let repo_path = temp_dir. path ( ) ;
275+
276+ Command :: new ( "git" )
277+ . args ( [ "init" , "-q" ] )
278+ . current_dir ( repo_path)
279+ . output ( )
280+ . expect ( "failed to init git repo" ) ;
281+ Command :: new ( "git" )
282+ . args ( [ "config" , "user.email" , "test@test.com" ] )
283+ . current_dir ( repo_path)
284+ . output ( )
285+ . expect ( "failed to set email" ) ;
286+ Command :: new ( "git" )
287+ . args ( [ "config" , "user.name" , "Test" ] )
288+ . current_dir ( repo_path)
289+ . output ( )
290+ . expect ( "failed to set name" ) ;
291+
292+ std:: fs:: write ( repo_path. join ( "file.txt" ) , "content\n " ) . expect ( "write" ) ;
293+ Command :: new ( "git" )
294+ . args ( [ "add" , "." ] )
295+ . current_dir ( repo_path)
296+ . output ( )
297+ . expect ( "failed to add" ) ;
298+ Command :: new ( "git" )
299+ . args ( [ "commit" , "-q" , "-m" , "only commit" ] )
300+ . current_dir ( repo_path)
301+ . output ( )
302+ . expect ( "failed to commit" ) ;
303+
304+ let input = DiffAnalysisInput {
305+ file_path : "file.txt" . to_string ( ) ,
306+ repo_path : Some ( repo_path. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
307+ base_commit : Some ( "HEAD~1" . to_string ( ) ) ,
308+ head_commit : Some ( "HEAD" . to_string ( ) ) ,
309+ } ;
310+
311+ let result = analyze_diff ( input) ;
312+ assert ! ( result. is_err( ) , "HEAD~1 on a single-commit repo must error" ) ;
313+ let err = result. unwrap_err ( ) . to_string ( ) ;
314+ assert ! (
315+ err. contains( "revspec" ) || err. contains( "not found" ) ,
316+ "error should be meaningful, got: {err}"
317+ ) ;
318+ }
319+
266320#[ test]
267321fn test_valid_range_returns_files ( ) {
268322 let temp_dir = tempfile:: tempdir ( ) . expect ( "failed to create temp dir" ) ;
0 commit comments