mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: exec git command directly instead of call methods from WorkingCopy (#330)
This commit is contained in:
parent
dc32c3e95d
commit
f8bc48c49c
1 changed files with 45 additions and 57 deletions
|
@ -1147,17 +1147,6 @@ namespace SourceGit.Views
|
|||
if (!selection.HasChanges)
|
||||
return;
|
||||
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
var workcopyView = this.FindAncestorOfType<WorkingCopy>();
|
||||
if (workcopyView == null)
|
||||
return;
|
||||
|
||||
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
|
||||
workcopy?.StageChanges(new List<Models.Change> { change });
|
||||
}
|
||||
else
|
||||
{
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
if (repoView == null)
|
||||
return;
|
||||
|
@ -1168,6 +1157,12 @@ namespace SourceGit.Views
|
|||
|
||||
repo.SetWatcherEnabled(false);
|
||||
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
new Commands.Add(repo.FullPath, [change]).Exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
var tmpFile = Path.GetTempFileName();
|
||||
if (change.WorkTree == Models.ChangeState.Untracked)
|
||||
{
|
||||
|
@ -1186,11 +1181,11 @@ namespace SourceGit.Views
|
|||
|
||||
new Commands.Apply(diff.Repo, tmpFile, true, "nowarn", "--cache --index").Exec();
|
||||
File.Delete(tmpFile);
|
||||
}
|
||||
|
||||
repo.MarkWorkingCopyDirtyManually();
|
||||
repo.SetWatcherEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUnstageChunk(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
@ -1210,17 +1205,6 @@ namespace SourceGit.Views
|
|||
if (!selection.HasChanges)
|
||||
return;
|
||||
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
var workcopyView = this.FindAncestorOfType<WorkingCopy>();
|
||||
if (workcopyView == null)
|
||||
return;
|
||||
|
||||
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
|
||||
workcopy?.UnstageChanges(new List<Models.Change> { change });
|
||||
}
|
||||
else
|
||||
{
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
if (repoView == null)
|
||||
return;
|
||||
|
@ -1231,6 +1215,15 @@ namespace SourceGit.Views
|
|||
|
||||
repo.SetWatcherEnabled(false);
|
||||
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
if (change.DataForAmend != null)
|
||||
new Commands.UnstageChangesForAmend(repo.FullPath, [change]).Exec();
|
||||
else
|
||||
new Commands.Reset(repo.FullPath, [change]).Exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
var treeGuid = new Commands.QueryStagedFileBlobGuid(diff.Repo, change.Path).Result();
|
||||
var tmpFile = Path.GetTempFileName();
|
||||
if (change.Index == Models.ChangeState.Added)
|
||||
|
@ -1242,11 +1235,11 @@ namespace SourceGit.Views
|
|||
|
||||
new Commands.Apply(diff.Repo, tmpFile, true, "nowarn", "--cache --index --reverse").Exec();
|
||||
File.Delete(tmpFile);
|
||||
}
|
||||
|
||||
repo.MarkWorkingCopyDirtyManually();
|
||||
repo.SetWatcherEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDiscardChunk(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
@ -1266,17 +1259,6 @@ namespace SourceGit.Views
|
|||
if (!selection.HasChanges)
|
||||
return;
|
||||
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
var workcopyView = this.FindAncestorOfType<WorkingCopy>();
|
||||
if (workcopyView == null)
|
||||
return;
|
||||
|
||||
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
|
||||
workcopy?.Discard(new List<Models.Change> { change });
|
||||
}
|
||||
else
|
||||
{
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
if (repoView == null)
|
||||
return;
|
||||
|
@ -1287,6 +1269,12 @@ namespace SourceGit.Views
|
|||
|
||||
repo.SetWatcherEnabled(false);
|
||||
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
Commands.Discard.Changes(repo.FullPath, [change]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tmpFile = Path.GetTempFileName();
|
||||
if (change.Index == Models.ChangeState.Added)
|
||||
{
|
||||
|
@ -1305,10 +1293,10 @@ namespace SourceGit.Views
|
|||
|
||||
new Commands.Apply(diff.Repo, tmpFile, true, "nowarn", "--reverse").Exec();
|
||||
File.Delete(tmpFile);
|
||||
}
|
||||
|
||||
repo.MarkWorkingCopyDirtyManually();
|
||||
repo.SetWatcherEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue