sourcegit/src/Commands/Version.cs

18 lines
650 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
namespace SourceGit.Commands {
/// <summary>
/// 检测git是否可用并获取git版本信息
/// </summary>
public class Version : Command {
const string GitVersionPrefix = "git version ";
public string Query() {
Args = $"--version";
var result = ReadToEnd();
if (!result.IsSuccess || string.IsNullOrEmpty(result.Output)) return null;
var version = result.Output.Trim();
if (!version.StartsWith(GitVersionPrefix, StringComparison.Ordinal)) return null;
return version.Substring(GitVersionPrefix.Length);
}
}
}