@@ -1311,6 +1311,62 @@ fn test_git_repo_head_ref() {
13111311 ) ;
13121312}
13131313
1314+ #[ test]
1315+ fn test_partial_sha_resolution_with_real_git ( ) {
1316+ let dir = git_initialize_repo ( ) ;
1317+
1318+ git_create_commit ( dir. path ( ) , "test.txt" , b"test content" , "test commit" ) ;
1319+
1320+ // Get the full and short SHA
1321+ let full_sha_output = std:: process:: Command :: new ( "git" )
1322+ . args ( [ "rev-parse" , "HEAD" ] )
1323+ . current_dir ( dir. path ( ) )
1324+ . output ( )
1325+ . expect ( "Failed to get full SHA" ) ;
1326+ let full_sha = String :: from_utf8 ( full_sha_output. stdout )
1327+ . expect ( "Invalid UTF-8" )
1328+ . trim ( )
1329+ . to_owned ( ) ;
1330+ let short_sha_output = std:: process:: Command :: new ( "git" )
1331+ . args ( [ "rev-parse" , "--short" , "HEAD" ] )
1332+ . current_dir ( dir. path ( ) )
1333+ . output ( )
1334+ . expect ( "Failed to get short SHA" ) ;
1335+ let short_sha = String :: from_utf8 ( short_sha_output. stdout )
1336+ . expect ( "Invalid UTF-8" )
1337+ . trim ( )
1338+ . to_owned ( ) ;
1339+
1340+ // Test that partial SHA is treated as symbolic reference
1341+ let spec = CommitSpec {
1342+ repo : "test-repo" . to_owned ( ) ,
1343+ path : Some ( dir. path ( ) . to_path_buf ( ) ) ,
1344+ rev : short_sha. clone ( ) ,
1345+ prev_rev : None ,
1346+ } ;
1347+
1348+ match spec. reference ( ) {
1349+ GitReference :: Symbolic ( s) => {
1350+ assert_eq ! ( s, short_sha) ;
1351+
1352+ // Now test that it resolves to the correct full SHA
1353+ let repo = git2:: Repository :: open ( dir. path ( ) ) . expect ( "Failed to open git repo" ) ;
1354+ let resolved = repo
1355+ . revparse_single ( & short_sha)
1356+ . expect ( "Failed to resolve short SHA" ) ;
1357+ let resolved_sha = resolved. id ( ) . to_string ( ) ;
1358+
1359+ assert_eq ! (
1360+ resolved_sha, full_sha,
1361+ "Partial SHA {short_sha} should resolve to full SHA {full_sha}, but got {resolved_sha}"
1362+ ) ;
1363+ }
1364+ GitReference :: Commit ( _) => {
1365+ panic ! ( "Partial SHA should be treated as symbolic reference" )
1366+ }
1367+ }
1368+ }
1369+
13141370#[ cfg( test) ]
13151371mod tests {
13161372 use super :: * ;
@@ -1459,60 +1515,4 @@ mod tests {
14591515 }
14601516 }
14611517 }
1462-
1463- #[ test]
1464- fn test_partial_sha_resolution_with_real_git ( ) {
1465- let dir = git_initialize_repo ( ) ;
1466-
1467- git_create_commit ( dir. path ( ) , "test.txt" , b"test content" , "test commit" ) ;
1468-
1469- // Get the full and short SHA
1470- let full_sha_output = std:: process:: Command :: new ( "git" )
1471- . args ( [ "rev-parse" , "HEAD" ] )
1472- . current_dir ( dir. path ( ) )
1473- . output ( )
1474- . expect ( "Failed to get full SHA" ) ;
1475- let full_sha = String :: from_utf8 ( full_sha_output. stdout )
1476- . expect ( "Invalid UTF-8" )
1477- . trim ( )
1478- . to_owned ( ) ;
1479- let short_sha_output = std:: process:: Command :: new ( "git" )
1480- . args ( [ "rev-parse" , "--short" , "HEAD" ] )
1481- . current_dir ( dir. path ( ) )
1482- . output ( )
1483- . expect ( "Failed to get short SHA" ) ;
1484- let short_sha = String :: from_utf8 ( short_sha_output. stdout )
1485- . expect ( "Invalid UTF-8" )
1486- . trim ( )
1487- . to_owned ( ) ;
1488-
1489- // Test that partial SHA is treated as symbolic reference
1490- let spec = CommitSpec {
1491- repo : "test-repo" . to_owned ( ) ,
1492- path : Some ( dir. path ( ) . to_path_buf ( ) ) ,
1493- rev : short_sha. clone ( ) ,
1494- prev_rev : None ,
1495- } ;
1496-
1497- match spec. reference ( ) {
1498- GitReference :: Symbolic ( s) => {
1499- assert_eq ! ( s, short_sha) ;
1500-
1501- // Now test that it resolves to the correct full SHA
1502- let repo = git2:: Repository :: open ( dir. path ( ) ) . expect ( "Failed to open git repo" ) ;
1503- let resolved = repo
1504- . revparse_single ( & short_sha)
1505- . expect ( "Failed to resolve short SHA" ) ;
1506- let resolved_sha = resolved. id ( ) . to_string ( ) ;
1507-
1508- assert_eq ! (
1509- resolved_sha, full_sha,
1510- "Partial SHA {short_sha} should resolve to full SHA {full_sha}, but got {resolved_sha}"
1511- ) ;
1512- }
1513- GitReference :: Commit ( _) => {
1514- panic ! ( "Partial SHA should be treated as symbolic reference" )
1515- }
1516- }
1517- }
15181518}
0 commit comments