@@ -1394,83 +1394,84 @@ public static void RemoveContextMenuRegistryAPKInstall(string contextRegRoot)
1394
1394
/// <returns></returns>
1395
1395
public static string ReadGitBranchInfo ( string projectPath , bool searchParentFolders )
1396
1396
{
1397
- string results = null ;
1398
-
1399
- if ( searchParentFolders )
1397
+ DirectoryInfo directoryInfo = new DirectoryInfo ( projectPath ) ;
1398
+ while ( directoryInfo != null )
1400
1399
{
1401
- DirectoryInfo directoryInfo = new DirectoryInfo ( projectPath ) ;
1400
+ string gitDir = Path . Combine ( directoryInfo . FullName , ".git" ) ;
1401
+ string headFile = Path . Combine ( gitDir , "HEAD" ) ;
1402
1402
1403
- while ( directoryInfo != null )
1403
+ if ( Directory . Exists ( gitDir ) && File . Exists ( headFile ) )
1404
1404
{
1405
- string dirName = Path . Combine ( directoryInfo . FullName , ".git" ) ;
1405
+ string headContent = File . ReadAllText ( headFile ) . Trim ( ) ;
1406
+ int pos = headContent . LastIndexOf ( '/' ) + 1 ;
1407
+ return ( pos < headContent . Length ) ? headContent . Substring ( pos ) : headContent ;
1408
+ }
1406
1409
1407
- if ( Directory . Exists ( dirName ) )
1408
- {
1409
- string branchFile = Path . Combine ( dirName , "HEAD" ) ;
1410
- if ( File . Exists ( branchFile ) )
1411
- {
1412
- // removes extra end of line
1413
- results = string . Join ( " " , File . ReadAllLines ( branchFile ) ) ;
1414
- // get branch only
1415
- int pos = results . LastIndexOf ( "/" ) + 1 ;
1416
- results = results . Substring ( pos , results . Length - pos ) ;
1417
- return results ;
1418
- }
1419
- }
1420
- directoryInfo = directoryInfo . Parent ;
1410
+ if ( ! searchParentFolders )
1411
+ {
1412
+ break ;
1421
1413
}
1414
+ directoryInfo = directoryInfo . Parent ;
1422
1415
}
1423
- else
1416
+
1417
+ return null ;
1418
+ }
1419
+
1420
+
1421
+ public static string ReadPlasticBranchInfo ( string projectPath , bool searchParentFolders )
1422
+ {
1423
+ string branchName = null ;
1424
+ DirectoryInfo directoryInfo = new DirectoryInfo ( projectPath ) ;
1425
+
1426
+ while ( directoryInfo != null )
1424
1427
{
1425
- string dirName = Path . Combine ( projectPath , ".git " ) ;
1426
- if ( Directory . Exists ( dirName ) )
1428
+ string plasticSelectorPath = Path . Combine ( directoryInfo . FullName , ".plastic" , "plastic.selector ") ;
1429
+ if ( File . Exists ( plasticSelectorPath ) )
1427
1430
{
1428
- string branchFile = Path . Combine ( dirName , "HEAD" ) ;
1429
- if ( File . Exists ( branchFile ) )
1431
+ branchName = ExtractPlasticBranch ( plasticSelectorPath ) ;
1432
+ if ( ! string . IsNullOrEmpty ( branchName ) )
1430
1433
{
1431
- // removes extra end of line
1432
- results = string . Join ( " " , File . ReadAllLines ( branchFile ) ) ;
1433
- // get branch only
1434
- int pos = results . LastIndexOf ( "/" ) + 1 ;
1435
- results = results . Substring ( pos , results . Length - pos ) ;
1436
-
1434
+ return branchName ;
1437
1435
}
1438
1436
}
1437
+
1438
+ if ( ! searchParentFolders )
1439
+ {
1440
+ break ;
1441
+ }
1442
+
1443
+ directoryInfo = directoryInfo . Parent ;
1439
1444
}
1440
- return results ;
1445
+
1446
+ return branchName ;
1441
1447
}
1442
1448
1443
- public static string ReadPlasticBranchInfo ( string projectPath )
1449
+ private static string ExtractPlasticBranch ( string plasticSelectorPath )
1444
1450
{
1445
- string branchName = null ;
1446
- string plasticSelectorPath = Path . Combine ( projectPath , ".plastic" , "plastic.selector" ) ;
1447
-
1448
- if ( File . Exists ( plasticSelectorPath ) )
1451
+ string [ ] lines = File . ReadAllLines ( plasticSelectorPath ) ;
1452
+ foreach ( string line in lines )
1449
1453
{
1450
- string [ ] lines = File . ReadAllLines ( plasticSelectorPath ) ;
1451
- foreach ( string line in lines )
1454
+ string trimmedLine = line . Trim ( ) ;
1455
+ if ( trimmedLine . StartsWith ( "br " ) || trimmedLine . StartsWith ( "smartbranch " ) )
1452
1456
{
1453
- string trimmedLine = line . Trim ( ) ;
1454
- if ( trimmedLine . StartsWith ( "br " ) || trimmedLine . StartsWith ( "smartbranch " ) )
1457
+ // Extract the first quoted string
1458
+ var match = Regex . Match ( trimmedLine , "\" ([^\" ]+)\" " ) ;
1459
+ if ( match . Success )
1455
1460
{
1456
- // Extract the branch name between quotes
1457
- var match = Regex . Match ( trimmedLine , "\" ([^ \" ]+) \" " ) ;
1458
- if ( match . Success )
1461
+ string branchName = match . Groups [ 1 ] . Value ;
1462
+ // Remove leading slash if present (e.g. , "/main" becomes "main")
1463
+ if ( branchName . StartsWith ( "/" ) )
1459
1464
{
1460
- branchName = match . Groups [ 1 ] . Value ;
1461
- // Remove the leading slash if present
1462
- if ( branchName . StartsWith ( "/" ) )
1463
- {
1464
- branchName = branchName . Substring ( 1 ) ;
1465
- }
1466
- break ;
1465
+ branchName = branchName . Substring ( 1 ) ;
1467
1466
}
1467
+ return branchName ;
1468
1468
}
1469
1469
}
1470
1470
}
1471
- return branchName ;
1471
+ return null ;
1472
1472
}
1473
1473
1474
+
1474
1475
//public static Platform GetTargetPlatform(string projectPath)
1475
1476
static string GetTargetPlatformRaw ( string projectPath )
1476
1477
{
0 commit comments