2024-02-05 23:08:37 -08:00
|
|
|
|
using System.IO;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public class QueryGitDir : Command
|
|
|
|
|
{
|
|
|
|
|
public QueryGitDir(string workDir)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = workDir;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = "rev-parse --git-dir";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
RaiseError = false;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string Result()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var rs = ReadToEnd().StdOut;
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (string.IsNullOrEmpty(rs))
|
|
|
|
|
return null;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
|
|
rs = rs.Trim();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (Path.IsPathRooted(rs))
|
|
|
|
|
return rs;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return Path.GetFullPath(Path.Combine(WorkingDirectory, rs));
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|