public void GitInstallation_CaseInsensitiveComparison() { List <GitInstallation> list = new List <GitInstallation> { new GitInstallation(@"C:\Program Files (x86)\Git", KnownGitDistribution.GitForWindows32v1), new GitInstallation(@"C:\Program Files (x86)\Git", KnownGitDistribution.GitForWindows32v2), new GitInstallation(@"C:\Program Files\Git", KnownGitDistribution.GitForWindows32v1), new GitInstallation(@"C:\Program Files\Git", KnownGitDistribution.GitForWindows32v2), new GitInstallation(@"C:\Program Files\Git", KnownGitDistribution.GitForWindows64v2), // ToLower versions new GitInstallation(@"C:\Program Files (x86)\Git".ToLower(), KnownGitDistribution.GitForWindows32v1), new GitInstallation(@"C:\Program Files (x86)\Git".ToLower(), KnownGitDistribution.GitForWindows32v2), new GitInstallation(@"C:\Program Files\Git".ToLower(), KnownGitDistribution.GitForWindows32v1), new GitInstallation(@"C:\Program Files\Git".ToLower(), KnownGitDistribution.GitForWindows32v2), new GitInstallation(@"C:\Program Files\Git".ToLower(), KnownGitDistribution.GitForWindows64v2), // ToUpper versions new GitInstallation(@"C:\Program Files (x86)\Git".ToUpper(), KnownGitDistribution.GitForWindows32v1), new GitInstallation(@"C:\Program Files (x86)\Git".ToUpper(), KnownGitDistribution.GitForWindows32v2), new GitInstallation(@"C:\Program Files\Git".ToUpper(), KnownGitDistribution.GitForWindows32v1), new GitInstallation(@"C:\Program Files\Git".ToUpper(), KnownGitDistribution.GitForWindows32v2), new GitInstallation(@"C:\Program Files\Git".ToUpper(), KnownGitDistribution.GitForWindows64v2), }; HashSet <GitInstallation> set = new HashSet <GitInstallation>(list); Assert.Equal(15, list.Count); Assert.Equal(5, set.Count); Assert.Equal(6, list.Where(x => x.Version == KnownGitDistribution.GitForWindows32v1).Count()); Assert.Equal(6, list.Where(x => x.Version == KnownGitDistribution.GitForWindows32v2).Count()); Assert.Equal(3, list.Where(x => x.Version == KnownGitDistribution.GitForWindows64v2).Count()); Assert.Equal(2, set.Where(x => x.Version == KnownGitDistribution.GitForWindows32v1).Count()); Assert.Equal(2, set.Where(x => x.Version == KnownGitDistribution.GitForWindows32v2).Count()); Assert.Equal(1, set.Where(x => x.Version == KnownGitDistribution.GitForWindows64v2).Count()); foreach (var v in Enum.GetValues(typeof(KnownGitDistribution))) { KnownGitDistribution kgd = (KnownGitDistribution)v; var a = list.Where(x => x.Version == kgd); Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Cmd, a.First().Cmd))); Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Config, a.First().Config))); Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Git, a.First().Git))); Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Libexec, a.First().Libexec))); Assert.True(a.All(x => x != a.First() || GitInstallation.PathComparer.Equals(x.Sh, a.First().Sh))); } }
internal GitInstallation(string path, KnownGitDistribution version) { Debug.Assert(!String.IsNullOrWhiteSpace(path), "The `path` parameter is null or invalid."); Debug.Assert(CommonConfigPaths.ContainsKey(version), "The `version` parameter not found in `CommonConfigPaths`."); Debug.Assert(CommonCmdPaths.ContainsKey(version), "The `version` parameter not found in `CommonCmdPaths`."); Debug.Assert(CommonLibexecPaths.ContainsKey(version), "The `version` parameter not found in `CommonLibExecPaths`."); // trim off trailing '\' characters to increase compatibility path = path.TrimEnd('\\'); Config = System.IO.Path.Combine(path, CommonConfigPaths[version]); Cmd = System.IO.Path.Combine(path, CommonCmdPaths[version]); Libexec = System.IO.Path.Combine(path, CommonLibexecPaths[version]); Path = path; Version = version; }
internal GitInstallation(string path, KnownGitDistribution version) { Debug.Assert(!String.IsNullOrWhiteSpace(path), $"The `{nameof(path)}` parameter is null or invalid."); Debug.Assert(CommonConfigPaths.ContainsKey(version), $"The `{nameof(version)}` parameter not found in `{nameof(CommonConfigPaths)}`."); Debug.Assert(CommonCmdPaths.ContainsKey(version), $"The `{nameof(version)}` parameter not found in `{nameof(CommonCmdPaths)}`."); Debug.Assert(CommonGitPaths.ContainsKey(version), $"The `{nameof(version)}` parameter not found in `{nameof(CommonGitPaths)}`."); Debug.Assert(CommonLibexecPaths.ContainsKey(version), $"The `{nameof(version)}` parameter not found in `{nameof(CommonLibexecPaths)}`."); Debug.Assert(CommonShPaths.ContainsKey(version), $"The `{nameof(version)}` parameter not found in `{nameof(CommonShPaths)}`."); Debug.Assert(CommonDocPaths.ContainsKey(version), $"The `{nameof(version)}` parameter not found in `{nameof(CommonDocPaths)}`."); path = path.TrimEnd('\\'); // Make sure the GitExeName isn't included as a part of the path. if (path.EndsWith(AllVersionGitPath, StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - AllVersionGitPath.Length); } // Versions of git installation could have 2 binaries. One in the `bin` directory and the // other in the `cmd` directory. Handle both scenarios. if (path.EndsWith(AllVersionBinGitPath, StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - AllVersionBinGitPath.Length); } if (path.EndsWith(GitExeName, StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - GitExeName.Length); } // trim off trailing '\' characters to increase compatibility path = path.TrimEnd('\\'); Path = path; Version = version; _cmd = null; _config = null; _doc = null; _git = null; _libexec = null; _sh = null; }
public static bool FindGitInstallation(string path, KnownGitDistribution distro, out GitInstallation installation) { installation = new GitInstallation(path, distro); return(GitInstallation.IsValid(installation)); }
public static bool FindGitInstallation(string path, KnownGitDistribution distro, out GitInstallation installation) { installation = new GitInstallation(path, distro); return GitInstallation.IsValid(installation); }
internal GitInstallation(string path, KnownGitDistribution version) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } if (!CommonConfigPaths.ContainsKey(version)) { throw new ArgumentOutOfRangeException(nameof(version)); } if (!CommonCmdPaths.ContainsKey(version)) { throw new ArgumentOutOfRangeException(nameof(version)); } if (!CommonGitPaths.ContainsKey(version)) { throw new ArgumentOutOfRangeException(nameof(version)); } if (!CommonLibexecPaths.ContainsKey(version)) { throw new ArgumentOutOfRangeException(nameof(version)); } if (!CommonShPaths.ContainsKey(version)) { throw new ArgumentOutOfRangeException(nameof(version)); } if (!CommonDocPaths.ContainsKey(version)) { throw new ArgumentOutOfRangeException(nameof(version)); } path = path.TrimEnd('\\'); // Make sure the GitExeName isn't included as a part of the path. if (path.EndsWith(AllVersionGitPath, StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - AllVersionGitPath.Length); } // Versions of git installation could have 2 binaries. One in the `bin` directory and the // other in the `cmd` directory. Handle both scenarios. if (path.EndsWith(AllVersionBinGitPath, StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - AllVersionBinGitPath.Length); } if (path.EndsWith(GitExeName, StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - GitExeName.Length); } // Trim off trailing '\' characters to increase compatibility. path = path.TrimEnd('\\'); _path = path; _distribution = version; _cmd = null; _config = null; _doc = null; _git = null; _libexec = null; _sh = null; }