/// <summary> /// Gets the working copy entry information on the specified path from its parent /// </summary> /// <param name="path">The path.</param> /// <returns></returns> public GitStatusEventArgs SafeGetEntry(string path) { if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path"); // We only have to look in the parent. // If the path is the working copy root, the name doesn't matter! string dir = GitTools.GetNormalizedDirectoryName(path); var sa = new GitStatusArgs(); sa.Depth = GitDepth.Files; sa.RetrieveAllEntries = false; sa.RetrieveIgnoredEntries = false; sa.ThrowOnError = false; sa.ThrowOnCancel = false; GitStatusEventArgs entry = null; _client.Status(dir, sa, (sender, e) => { if (entry == null && String.Equals(path, e.FullPath, FileSystemUtil.StringComparison)) { entry = e; e.Cancel = true; } }); return entry; }
/// <summary> /// Check if adding the path might succeed /// </summary> /// <param name="path"></param> /// <returns><c>false</c> when adding the file will fail, <c>true</c> if it could succeed</returns> public bool CouldAdd(string path, GitNodeKind nodeKind) { if (path == null) throw new ArgumentNullException("path"); GitItem item = StatusCache[path]; string file = item.Name; if (!item.Exists || item.IsVersioned) return true; // Item already exists.. Fast GitItem parent = item.Parent; if (BelowAdminDir(item)) return false; if (item.IsFile && parent != null && !parent.IsVersioned) return true; // Not in a versioned directory -> Fast out // Item does exist; check casing string parentDir = GitTools.GetNormalizedDirectoryName(path); GitStatusArgs wa = new GitStatusArgs(); wa.ThrowOnError = false; wa.ThrowOnCancel = false; wa.Depth = GitDepth.Files; bool ok = true; using (GitClient client = GetService<IGitClientPool>().GetNoUIClient()) { client.Status(parentDir, wa, delegate(object sender, GitStatusEventArgs e) { if (string.Equals(e.FullPath, path, StringComparison.OrdinalIgnoreCase)) { if (!string.Equals(e.Name, file, StringComparison.Ordinal)) { ok = false; // Casing issue } } }); } return ok; }
string GetGitCasing(GitItem item) { string name = null; // Find the correct casing using (GitClient client = Context.GetService<IGitClientPool>().GetNoUIClient()) { GitStatusArgs args = new GitStatusArgs(); args.Depth = GitDepth.Files; args.RetrieveAllEntries = false; args.RetrieveIgnoredEntries = false; args.ThrowOnCancel = false; args.ThrowOnError = false; client.Status(item.Directory, args, delegate(object sender, GitStatusEventArgs ea) { if (string.Equals(ea.FullPath, item.FullPath, StringComparison.OrdinalIgnoreCase)) { name = ea.FullPath; } }); } return name; }