private void diffResetSubmoduleChanges_Click(object sender, EventArgs e) { var submodules = DiffFiles.SelectedItems.Where(it => it.IsSubmodule).Select(it => it.Name).Distinct().ToList(); // Show a form asking the user if they want to reset the changes. FormResetChanges.ActionEnum resetType = FormResetChanges.ShowResetDialog(this, true, true); if (resetType == FormResetChanges.ActionEnum.Cancel) { return; } foreach (var name in submodules) { GitModule module = Module.GetSubmodule(name); // Reset all changes. module.Reset(ResetMode.Hard); // Also delete new files, if requested. if (resetType == FormResetChanges.ActionEnum.ResetAndDelete) { module.Clean(CleanMode.OnlyNonIgnored, directories: true); } } RefreshArtificial(); }
/// <summary> /// Shows the dialog modally under the given owner, and returns the user's selection (RESET, RESET_AND_DELETE, or CANCEL). /// </summary> /// <param name="owner">Shows this form as a modal dialog with the specified owner.</param> /// <param name="hasExistingFiles">Are there existing (modified) files selected?</param> /// <param name="hasNewFiles">Are there new (untracked) files selected?</param> public static ActionEnum ShowResetDialog(IWin32Window owner, bool hasExistingFiles, bool hasNewFiles) { using (var form = new FormResetChanges(hasExistingFiles, hasNewFiles)) { form.ShowDialog(owner); return(form.SelectedAction); } }
/// <summary> /// Shows the dialog modally under the given owner, and returns the user's selection (RESET, RESET_AND_DELETE, or CANCEL). /// </summary> /// <param name="owner">Shows this form as a modal dialog with the specified owner.</param> /// <param name="hasExistingFiles">Are there existing (modified) files selected?</param> /// <param name="hasNewFiles">Are there new (untracked) files selected?</param> public static ActionEnum ShowResetDialog(IWin32Window owner, bool hasExistingFiles, bool hasNewFiles) { using (FormResetChanges form = new FormResetChanges(hasExistingFiles, hasNewFiles)) { form.ShowDialog(owner); return form.SelectedAction; } }
private void diffResetSubmoduleChanges_Click(object sender, EventArgs e) { var unStagedFiles = DiffFiles.SelectedItems.ToList(); if (unStagedFiles.Count == 0) { return; } // Show a form asking the user if they want to reset the changes. FormResetChanges.ActionEnum resetType = FormResetChanges.ShowResetDialog(this, true, true); if (resetType == FormResetChanges.ActionEnum.Cancel) { return; } foreach (var item in unStagedFiles.Where(it => it.IsSubmodule)) { GitModule module = Module.GetSubmodule(item.Name); // Reset all changes. module.ResetHard(""); // Also delete new files, if requested. if (resetType == FormResetChanges.ActionEnum.ResetAndDelete) { var unstagedFiles = module.GetUnstagedFiles(); foreach (var file in unstagedFiles.Where(file => file.IsNew)) { try { string path = Path.Combine(module.WorkingDir, file.Name); if (File.Exists(path)) { File.Delete(path); } else { Directory.Delete(path, true); } } catch (System.IO.IOException) { } catch (System.UnauthorizedAccessException) { } } } } //TBD RefreshRevisions(); }
private void diffResetSubmoduleChanges_Click(object sender, EventArgs e) { var submodules = DiffFiles.SelectedItems.Where(it => it.IsSubmodule).Select(it => it.Name).Distinct().ToList(); // Show a form asking the user if they want to reset the changes. FormResetChanges.ActionEnum resetType = FormResetChanges.ShowResetDialog(this, true, true); if (resetType == FormResetChanges.ActionEnum.Cancel) { return; } foreach (var name in submodules) { GitModule module = Module.GetSubmodule(name); // Reset all changes. module.ResetHard(""); // Also delete new files, if requested. if (resetType == FormResetChanges.ActionEnum.ResetAndDelete) { var unstagedFiles = module.GetUnstagedFiles(); foreach (var file in unstagedFiles.Where(file => file.IsNew)) { try { string path = _fullPathResolver.Resolve(file.Name); if (File.Exists(path)) { File.Delete(path); } else { Directory.Delete(path, true); } } catch (IOException) { } catch (UnauthorizedAccessException) { } } } } RefreshArtificial(); }