/// <summary> /// Deletes a file or many. /// </summary> /// <param name="action"></param> private void DeleteFile(object action) { var dialog = new ConfirmDialog { Title = "Delete file(s)", Message = "Are you sure you want to delete the selected file(s)?\r\n\r\nYou may lose your changes!", ButtonSet = ConfirmDialog.ButtonsSet.OK_CANCEL }; dialog.ShowDialog(); var pressedButton = (Button) dialog.PressedButton; if (pressedButton != null && ((string) pressedButton.Content) == "OK") { var collection = (IList) action; var items = collection.Cast<StatusItem>(); LibGit2Sharp.Repository repo = null; // Loop through all selected status items and remove the files physically (and in some cases also from the repository). foreach (StatusItem item in items) { // TODO: --cached ? File.Delete(RepositoryFullPath + "/" + item.Filename); if (!item.Status.HasFlag(LibGit2Sharp.FileStatus.Untracked)) { if (!(repo is LibGit2Sharp.Repository)) repo = new LibGit2Sharp.Repository(RepositoryFullPath); repo.Index.Unstage(RepositoryFullPath + "/" + item.Filename); } } if (repo is LibGit2Sharp.Repository) repo.Dispose(); } }
/// <summary> /// Deletes a tag. /// </summary> /// <param name="action"></param> public void DeleteTag(object action) { var tag = (Tag) action; var dialog = new ConfirmDialog { Title = "Deleting a tag", Message = String.Format("Are you sure you want to delete this tag ({0})?", tag.Name) }; dialog.ShowDialog(); var pressedButton = dialog.PressedButton; if (pressedButton == null || ((string) pressedButton.Content) != "OK") return; Task.Run(() => { using (var repo = new LibGit2Sharp.Repository(RepositoryFullPath)) { // Remove the tag from the Git repository. repo.Tags.Delete(tag.CanonicalName); // Reload all tags. LoadTags(); Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Normal, (Action) (() => tag.Target.Tags.Remove(tag)) ); } }); }