mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 22:01:10 +08:00
fix<Discard>: wrong discard behavior with changes both in worktree and staged
This commit is contained in:
@@ -13,9 +13,17 @@ namespace SourceGit.ViewModels {
|
||||
private set;
|
||||
}
|
||||
|
||||
public Discard(Repository repo, List<Models.Change> changes = null) {
|
||||
public Discard(Repository repo) {
|
||||
_repo = repo;
|
||||
|
||||
Mode = new DiscardModeAll();
|
||||
View = new Views.Discard { DataContext = this };
|
||||
}
|
||||
|
||||
public Discard(Repository repo, List<Models.Change> changes, bool isUnstaged) {
|
||||
_repo = repo;
|
||||
_changes = changes;
|
||||
_isUnstaged = isUnstaged;
|
||||
|
||||
if (_changes == null) {
|
||||
Mode = new DiscardModeAll();
|
||||
@@ -35,8 +43,10 @@ namespace SourceGit.ViewModels {
|
||||
return Task.Run(() => {
|
||||
if (_changes == null) {
|
||||
Commands.Discard.All(_repo.FullPath);
|
||||
} else if (_isUnstaged) {
|
||||
Commands.Discard.ChangesInWorkTree(_repo.FullPath, _changes);
|
||||
} else {
|
||||
Commands.Discard.Changes(_repo.FullPath, _changes);
|
||||
Commands.Discard.ChangesInStaged(_repo.FullPath, _changes);
|
||||
}
|
||||
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
@@ -46,5 +56,6 @@ namespace SourceGit.ViewModels {
|
||||
|
||||
private Repository _repo = null;
|
||||
private List<Models.Change> _changes = null;
|
||||
private bool _isUnstaged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,12 +271,20 @@ namespace SourceGit.ViewModels {
|
||||
IsUnstaging = false;
|
||||
}
|
||||
|
||||
public void Discard(List<Models.Change> changes) {
|
||||
public void Discard(List<Models.Change> changes, bool isUnstaged) {
|
||||
if (PopupHost.CanCreatePopup()) {
|
||||
if (changes.Count == _count) {
|
||||
PopupHost.ShowPopup(new Discard(_repo));
|
||||
if (isUnstaged) {
|
||||
if (changes.Count == _unstaged.Count && _staged.Count == 0) {
|
||||
PopupHost.ShowPopup(new Discard(_repo));
|
||||
} else {
|
||||
PopupHost.ShowPopup(new Discard(_repo, changes, true));
|
||||
}
|
||||
} else {
|
||||
PopupHost.ShowPopup(new Discard(_repo, changes));
|
||||
if (changes.Count == _staged.Count && _unstaged.Count == 0) {
|
||||
PopupHost.ShowPopup(new Discard(_repo));
|
||||
} else {
|
||||
PopupHost.ShowPopup(new Discard(_repo, changes, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -397,7 +405,7 @@ namespace SourceGit.ViewModels {
|
||||
discard.Header = App.Text("FileCM.Discard");
|
||||
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
||||
discard.Click += (_, e) => {
|
||||
Discard(changes);
|
||||
Discard(changes, true);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -483,7 +491,7 @@ namespace SourceGit.ViewModels {
|
||||
discard.Header = App.Text("FileCM.DiscardMulti", changes.Count);
|
||||
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
||||
discard.Click += (_, e) => {
|
||||
Discard(changes);
|
||||
Discard(changes, true);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -561,6 +569,14 @@ namespace SourceGit.ViewModels {
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
var discard = new MenuItem();
|
||||
discard.Header = App.Text("FileCM.Discard");
|
||||
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
||||
discard.Click += (_, e) => {
|
||||
Discard(changes, false);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
var stash = new MenuItem();
|
||||
stash.Header = App.Text("FileCM.Stash");
|
||||
stash.Icon = App.CreateMenuIcon("Icons.Stashes");
|
||||
@@ -604,6 +620,7 @@ namespace SourceGit.ViewModels {
|
||||
menu.Items.Add(openWith);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
menu.Items.Add(unstage);
|
||||
menu.Items.Add(discard);
|
||||
menu.Items.Add(stash);
|
||||
menu.Items.Add(patch);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
@@ -617,6 +634,14 @@ namespace SourceGit.ViewModels {
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
var discard = new MenuItem();
|
||||
discard.Header = App.Text("FileCM.DiscardMulti", changes.Count);
|
||||
discard.Icon = App.CreateMenuIcon("Icons.Undo");
|
||||
discard.Click += (_, e) => {
|
||||
Discard(changes, false);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
var stash = new MenuItem();
|
||||
stash.Header = App.Text("FileCM.StashMulti", changes.Count);
|
||||
stash.Icon = App.CreateMenuIcon("Icons.Stashes");
|
||||
@@ -649,6 +674,7 @@ namespace SourceGit.ViewModels {
|
||||
};
|
||||
|
||||
menu.Items.Add(unstage);
|
||||
menu.Items.Add(discard);
|
||||
menu.Items.Add(stash);
|
||||
menu.Items.Add(patch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user