public bool SafeDeleteFile(string path) { if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path"); GitDeleteArgs da = new GitDeleteArgs(); da.Force = true; da.KeepLocal = false; da.ThrowOnError = false; da.KeepLocal = !File.Exists(path); // This will stop the error if the file was already deleted return _client.Delete(path, da); }
public bool WcDelete(string path) { GitDeleteArgs da = new GitDeleteArgs(); da.ThrowOnError = false; da.Force = true; return _client.Delete(path, da); }
/// <summary> /// Fixes up missing files by fixing their casing or deleting them /// </summary> /// <param name="state">The state.</param> /// <returns></returns> private bool PreCommit_HandleMissingFiles(PendingCommitState state) { foreach (string path in new List<string>(state.CommitPaths)) { GitItem item = state.Cache[path]; if (item.Status.State != GitStatus.Missing) continue; if (item.IsCasingConflicted) { string correctCasing = GetGitCasing(item); string actualCasing = GitTools.GetTruePath(item.FullPath); if (correctCasing == null || actualCasing == null || !string.Equals(correctCasing, actualCasing, StringComparison.OrdinalIgnoreCase)) continue; // Nothing to fix here :( string correctFile = Path.GetFileName(correctCasing); string actualFile = Path.GetFileName(actualCasing); if (correctFile == actualFile) continue; // Casing issue is not in the file; can't fix :( IVisualGitOpenDocumentTracker odt = GetService<IVisualGitOpenDocumentTracker>(); using (odt.LockDocument(correctCasing, DocumentLockType.NoReload)) using (odt.LockDocument(actualCasing, DocumentLockType.NoReload)) { try { File.Move(actualCasing, correctCasing); // Fix the name in the commit list state.CommitPaths[state.CommitPaths.IndexOf(path)] = actualCasing; } catch { } finally { item.MarkDirty(); GetService<IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath); } } } else if (!item.Exists) { GitDeleteArgs da = new GitDeleteArgs(); da.KeepLocal = true; try { state.Client.Delete(path, da); } catch (GitException ex) { GetService<IVisualGitErrorHandler>().OnWarning(ex); return false; } } } return true; }