private void StashedSelectedIndexChanged(object sender, EventArgs e) { GitStash gitStash = Stashes.SelectedItem as GitStash; GitItemStatus stashedItem = Stashed.SelectedItem; Cursor.Current = Cursors.WaitCursor; if (stashedItem != null && gitStash == currentWorkingDirStashItem) //current working dir { View.ViewCurrentChanges(stashedItem); } else if (stashedItem != null) { if (stashedItem.IsNew && !stashedItem.IsTracked) { if (!stashedItem.IsSubmodule) { View.ViewGitItem(stashedItem.Name, stashedItem.TreeGuid); } else { View.ViewText(stashedItem.Name, GitCommandHelpers.GetSubmoduleText(Module, stashedItem.Name, stashedItem.TreeGuid)); } } else { string extraDiffArguments = View.GetExtraDiffArguments(); Encoding encoding = this.View.Encoding; View.ViewPatch(() => { Patch patch = Module.GetSingleDiff(gitStash.Name, gitStash.Name + "^", stashedItem.Name, stashedItem.OldName, extraDiffArguments, encoding, false); if (patch == null) { return(String.Empty); } if (stashedItem.IsSubmodule) { return(GitCommandHelpers.ProcessSubmodulePatch(Module, patch)); } return(patch.Text); }); } } else { View.ViewText(string.Empty, string.Empty); } Cursor.Current = Cursors.Default; }
public static GitStashInfo GetStashDetails(GitStash stash) { GitStashInfo res = null; var cmd = "git"; var args = $"-C \"{stash.GitDirectory}\" stash show {stash.Id}"; ScriptHelper.ExecuteScript(cmd, args, ScriptExecutionSettings.OneOutputStream, s => { res = GitStashInfo.ParseFromCmdResult(s, stash.GitDirectory); EnumerableExtensions.Apply(res.Changes, change => change.Image = FileHelper.GetFileIconForExtensionOrFilename(Path.GetExtension(change.FileName)).ToBitmap().ToImageSource()); res.Stash = stash; }); return(res); }
/// <summary>Adds the specified <paramref name="stashNode"/> to the stashes tree.</summary> TreeNode OnAddStash(TreeNodeCollection nodes, StashNode stashNode) { GitStash stash = stashNode.Value; TreeNode treeNode = new TreeNode(stash.Name) { Name = string.Format("stash{0}", stash.Index), Tag = stashNode, ToolTipText = stash.Message, ContextMenuStrip = menuStash, ImageKey = stashKey, SelectedImageKey = stashKey, }; nodes.Add(treeNode); return(treeNode); }
public static IEnumerable <GitStash> GetStashes(string gitWorkingDirectory) { var res = new List <GitStash>(); var cmd = "git"; string format = "--pretty=format:\"%h:%gd:%s:%cr:%an"; var args = $"-C \"{gitWorkingDirectory}\" stash list {format}"; ScriptHelper.ExecuteScript(cmd, args, ScriptExecutionSettings.Default, s => { var stash = GitStash.ParseFromCmdResultLine(s, format); if (stash != null) { stash.GitDirectory = gitWorkingDirectory; res.Add(stash); } }); return(res); }
private void LoadGitItemStatuses(IReadOnlyList <GitItemStatus> gitItemStatuses) { GitStash gitStash = Stashes.SelectedItem as GitStash; if (gitStash == _currentWorkingDirStashItem) { // FileStatusList has no interface for both worktree<-index, index<-HEAD at the same time // Must be handled when displaying var headId = Module.RevParse("HEAD"); var headRev = new GitRevision(headId); var indexRev = new GitRevision(ObjectId.IndexId) { ParentIds = new[] { headId } }; var workTreeRev = new GitRevision(ObjectId.WorkTreeId) { ParentIds = new[] { ObjectId.IndexId } }; var indexItems = gitItemStatuses.Where(item => item.Staged == StagedStatus.Index).ToList(); var workTreeItems = gitItemStatuses.Where(item => item.Staged != StagedStatus.Index).ToList(); Stashed.SetStashDiffs(headRev, indexRev, ResourceManager.Strings.Index, indexItems, workTreeRev, ResourceManager.Strings.Workspace, workTreeItems); } else { var firstId = Module.RevParse(gitStash.Name + "^"); var selectedId = Module.RevParse(gitStash.Name); var firstRev = firstId == null ? null : new GitRevision(firstId); var secondRev = selectedId == null ? null : new GitRevision(selectedId) { ParentIds = new[] { firstId } }; Stashed.SetDiffs(firstRev, secondRev, gitItemStatuses); } Loading.Visible = false; Loading.IsAnimating = false; Stashes.Enabled = true; refreshToolStripButton.Enabled = true; }
private void InitializeSoft() { GitStash gitStash = Stashes.SelectedItem as GitStash; Stashed.SetDiffs(); Loading.Visible = true; Stashes.Enabled = false; refreshToolStripButton.Enabled = false; toolStripButton_customMessage.Enabled = false; if (gitStash == _currentWorkingDirStashItem) { toolStripButton_customMessage.Enabled = true; _asyncLoader.LoadAsync(() => Module.GetAllChangedFiles(), LoadGitItemStatuses); Clear.Enabled = false; // disallow Drop (of current working directory) Apply.Enabled = false; // disallow Apply (of current working directory) } else if (gitStash != null) { _asyncLoader.LoadAsync(() => Module.GetStashDiffFiles(gitStash.Name), LoadGitItemStatuses); Clear.Enabled = true; // allow Drop Apply.Enabled = true; // allow Apply } }
private void InitializeSoft() { GitStash gitStash = Stashes.SelectedItem as GitStash; Stashed.GitItemStatuses = null; Loading.Visible = true; Stashes.Enabled = false; toolStripButton1.Enabled = false; toolStripButton_customMessage.Enabled = false; if (gitStash == null) { Stashed.GitItemStatuses = null; } else if (gitStash == currentWorkingDirStashItem) { toolStripButton_customMessage.Enabled = true; AsyncLoader.DoAsync(() => Module.GetAllChangedFiles(), LoadGitItemStatuses); } else { AsyncLoader.DoAsync(() => Module.GetStashDiffFiles(gitStash.Name), LoadGitItemStatuses); } }
public StashNode(GitStash stash, GitUICommands uiCommands) : base(stash, null, uiCommands) { IsDraggable = true; }
private void StashedSelectedIndexChanged(object sender, EventArgs e) { GitStash gitStash = Stashes.SelectedItem as GitStash; GitItemStatus stashedItem = Stashed.SelectedItem; EnablePartialStash(); using (WaitCursorScope.Enter()) { if (stashedItem != null && gitStash == _currentWorkingDirStashItem) { // current working directory View.ViewCurrentChanges(stashedItem, isStaged: false, openWithDifftool: null); } else if (stashedItem != null) { if (stashedItem.IsNew) { if (!stashedItem.IsSubmodule) { View.ViewGitItemAsync(stashedItem.Name, stashedItem.TreeGuid); } else { ThreadHelper.JoinableTaskFactory.RunAsync( () => View.ViewTextAsync( stashedItem.Name, LocalizationHelpers.GetSubmoduleText(Module, stashedItem.Name, stashedItem.TreeGuid?.ToString()))); } } else { string extraDiffArguments = View.GetExtraDiffArguments(); Encoding encoding = View.Encoding; ThreadHelper.JoinableTaskFactory.Run( () => { Patch patch = Module.GetSingleDiff(gitStash.Name + "^", gitStash.Name, stashedItem.Name, stashedItem.OldName, extraDiffArguments, encoding, true, stashedItem.IsTracked); if (patch == null) { return(View.ViewPatchAsync(fileName: null, text: string.Empty, openWithDifftool: null /* not applicable */, isText: true)); } if (stashedItem.IsSubmodule) { return(View.ViewPatchAsync(fileName: null, text: LocalizationHelpers.ProcessSubmodulePatch(Module, stashedItem.Name, patch), openWithDifftool: null /* not implemented */, isText: stashedItem.IsSubmodule)); } return(View.ViewPatchAsync(fileName: stashedItem.Name, text: patch.Text, openWithDifftool: null /* not implemented */, isText: stashedItem.IsSubmodule)); }); } } else { View.Clear(); } } }
public void Identifies_invalid_stash_strings(string rawStash) { Assert.IsFalse(GitStash.TryParse(rawStash, out var stash)); Assert.Null(stash); }