2024-02-05 23:08:37 -08:00
|
|
|
|
using System.IO;
|
2021-04-29 05:05:55 -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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Result() {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var rs = ReadToEnd().StdOut;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
if (string.IsNullOrEmpty(rs)) return null;
|
|
|
|
|
|
|
|
|
|
rs = rs.Trim();
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|