Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d1cae3b

Browse files
add searchparentfolder support for plastic branch search fixes #185
1 parent c5f2707 commit d1cae3b

File tree

2 files changed

+54
-53
lines changed

2 files changed

+54
-53
lines changed

‎UnityLauncherPro/GetProjects.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static Project GetProjectInfo(string projectPath, bool getGitBranch = false, boo
170170
// check for plastic, if enabled
171171
if (getPlasticBranch == true && gitBranch == null)
172172
{
173-
gitBranch = folderExists ? Tools.ReadPlasticBranchInfo(projectPath) : null;
173+
gitBranch = folderExists ? Tools.ReadPlasticBranchInfo(projectPath,searchGitbranchRecursively) : null;
174174
}
175175
}
176176

‎UnityLauncherPro/Tools.cs‎

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,83 +1394,84 @@ public static void RemoveContextMenuRegistryAPKInstall(string contextRegRoot)
13941394
/// <returns></returns>
13951395
public static string ReadGitBranchInfo(string projectPath, bool searchParentFolders)
13961396
{
1397-
string results = null;
1398-
1399-
if (searchParentFolders)
1397+
DirectoryInfo directoryInfo = new DirectoryInfo(projectPath);
1398+
while (directoryInfo != null)
14001399
{
1401-
DirectoryInfo directoryInfo = new DirectoryInfo(projectPath);
1400+
string gitDir = Path.Combine(directoryInfo.FullName, ".git");
1401+
string headFile = Path.Combine(gitDir, "HEAD");
14021402

1403-
while(directoryInfo!=null)
1403+
if(Directory.Exists(gitDir)&&File.Exists(headFile))
14041404
{
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+
}
14061409

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;
14211413
}
1414+
directoryInfo = directoryInfo.Parent;
14221415
}
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)
14241427
{
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))
14271430
{
1428-
stringbranchFile=Path.Combine(dirName,"HEAD");
1429-
if (File.Exists(branchFile))
1431+
branchName=ExtractPlasticBranch(plasticSelectorPath);
1432+
if (!string.IsNullOrEmpty(branchName))
14301433
{
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;
14371435
}
14381436
}
1437+
1438+
if (!searchParentFolders)
1439+
{
1440+
break;
1441+
}
1442+
1443+
directoryInfo = directoryInfo.Parent;
14391444
}
1440-
return results;
1445+
1446+
return branchName;
14411447
}
14421448

1443-
public static string ReadPlasticBranchInfo(string projectPath)
1449+
private static string ExtractPlasticBranch(string plasticSelectorPath)
14441450
{
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)
14491453
{
1450-
string[]lines = File.ReadAllLines(plasticSelectorPath);
1451-
foreach(stringlineinlines)
1454+
stringtrimmedLine = line.Trim();
1455+
if(trimmedLine.StartsWith("br ")||trimmedLine.StartsWith("smartbranch "))
14521456
{
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)
14551460
{
1456-
// Extract the branch name between quotes
1457-
varmatch=Regex.Match(trimmedLine, "\"([^\"]+)\"");
1458-
if (match.Success)
1461+
stringbranchName=match.Groups[1].Value;
1462+
// Remove leading slash if present (e.g., "/main" becomes "main")
1463+
if (branchName.StartsWith("/"))
14591464
{
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);
14671466
}
1467+
return branchName;
14681468
}
14691469
}
14701470
}
1471-
return branchName;
1471+
return null;
14721472
}
14731473

1474+
14741475
//public static Platform GetTargetPlatform(string projectPath)
14751476
static string GetTargetPlatformRaw(string projectPath)
14761477
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /