Files
sourcegit/src/Commands/QueryGitDir.cs
2025-08-21 23:38:24 +08:00

31 lines
699 B
C#

using System.IO;
namespace SourceGit.Commands
{
public class QueryGitDir : Command
{
public QueryGitDir(string workDir)
{
WorkingDirectory = workDir;
Args = "rev-parse --git-dir";
}
public string GetResult()
{
return Parse(ReadToEnd());
}
private string Parse(Result rs)
{
if (!rs.IsSuccess)
return null;
var stdout = rs.StdOut.Trim();
if (string.IsNullOrEmpty(stdout))
return null;
return Path.IsPathRooted(stdout) ? stdout : Path.GetFullPath(Path.Combine(WorkingDirectory, stdout));
}
}
}