Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.

Improved GitBranch detection robusness. #43

Merged
merged 1 commit into from
Mar 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions UnityLauncher/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,44 @@ public static void OpenURL(string url)
public static string ReadGitBranchInfo(string projectPath)
{
string results = null;
string branchFile = Path.Combine(projectPath, ".git", "HEAD");
if (File.Exists(branchFile) == true)
DirectoryInfo gitDirectory = FindDir(".git", projectPath);
if (gitDirectory != null )
{
results = File.ReadAllText(branchFile);
// get branch only
int pos = results.LastIndexOf("/") + 1;
results = results.Substring(pos, results.Length - pos);
string branchFile = Path.Combine(gitDirectory.FullName, "HEAD");
if (File.Exists(branchFile))
{
results = File.ReadAllText(branchFile);
// get branch only
int pos = results.LastIndexOf("/") + 1;
results = results.Substring(pos, results.Length - pos);
}
}
return results;
}

/// <summary>
/// Searches for a directory beginning with "startPath".
/// If the directory is not found, then parent folders are searched until
/// either it is found or the root folder has been reached.
/// Null is returned if the directory was not found.
/// </summary>
/// <param name="dirName"></param>
/// <param name="startPath"></param>
/// <returns></returns>
public static DirectoryInfo FindDir(string dirName, string startPath)
{
DirectoryInfo dirInfo = new DirectoryInfo(Path.Combine(startPath, dirName));
while ( !dirInfo.Exists )
{
if(dirInfo.Parent.Parent == null )
{
return null;
}
dirInfo = new DirectoryInfo(Path.Combine(dirInfo.Parent.Parent.FullName, dirName));
}
return dirInfo;
}

/// <summary>
/// returns last-write-time for a file or folder
/// </summary>
Expand Down