mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
Reset to Parent Revision
* support reset to parent revision for Added files too * support reset to parent revision in Files tab * support reset to parent revision in Changes - now supports Renamings too now it behaves more like git-extensions
This commit is contained in:
parent
089f24b0d2
commit
8c9e8e5dbc
2 changed files with 43 additions and 23 deletions
|
@ -58,7 +58,7 @@ namespace SourceGit.Commands
|
||||||
|
|
||||||
public bool FileWithRevision(string file, string revision)
|
public bool FileWithRevision(string file, string revision)
|
||||||
{
|
{
|
||||||
Args = $"checkout {revision} -- \"{file}\"";
|
Args = $"checkout --no-overlay {revision} -- \"{file}\"";
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -270,25 +271,6 @@ namespace SourceGit.ViewModels
|
||||||
var fullPath = Path.Combine(_repo.FullPath, change.Path);
|
var fullPath = Path.Combine(_repo.FullPath, change.Path);
|
||||||
if (File.Exists(fullPath))
|
if (File.Exists(fullPath))
|
||||||
{
|
{
|
||||||
var resetToThisRevision = new MenuItem();
|
|
||||||
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
|
|
||||||
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
|
||||||
resetToThisRevision.Click += (_, ev) =>
|
|
||||||
{
|
|
||||||
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}");
|
|
||||||
ev.Handled = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
var resetToFirstParent = new MenuItem();
|
|
||||||
resetToFirstParent.Header = App.Text("ChangeCM.CheckoutFirstParentRevision");
|
|
||||||
resetToFirstParent.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
|
||||||
resetToFirstParent.IsEnabled = _commit.Parents.Count > 0 && change.Index != Models.ChangeState.Added && change.Index != Models.ChangeState.Renamed;
|
|
||||||
resetToFirstParent.Click += (_, ev) =>
|
|
||||||
{
|
|
||||||
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}~1");
|
|
||||||
ev.Handled = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
var explore = new MenuItem();
|
var explore = new MenuItem();
|
||||||
explore.Header = App.Text("RevealFile");
|
explore.Header = App.Text("RevealFile");
|
||||||
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
||||||
|
@ -298,8 +280,6 @@ namespace SourceGit.ViewModels
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
menu.Items.Add(resetToThisRevision);
|
|
||||||
menu.Items.Add(resetToFirstParent);
|
|
||||||
menu.Items.Add(new MenuItem { Header = "-" });
|
menu.Items.Add(new MenuItem { Header = "-" });
|
||||||
menu.Items.Add(explore);
|
menu.Items.Add(explore);
|
||||||
menu.Items.Add(new MenuItem { Header = "-" });
|
menu.Items.Add(new MenuItem { Header = "-" });
|
||||||
|
@ -332,6 +312,29 @@ namespace SourceGit.ViewModels
|
||||||
menu.Items.Add(new MenuItem { Header = "-" });
|
menu.Items.Add(new MenuItem { Header = "-" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resetToThisRevision = new MenuItem();
|
||||||
|
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
|
||||||
|
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
||||||
|
resetToThisRevision.Click += (_, ev) =>
|
||||||
|
{
|
||||||
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}");
|
||||||
|
ev.Handled = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
var resetToFirstParent = new MenuItem();
|
||||||
|
resetToFirstParent.Header = App.Text("ChangeCM.CheckoutFirstParentRevision");
|
||||||
|
resetToFirstParent.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
||||||
|
resetToFirstParent.IsEnabled = _commit.Parents.Count > 0;
|
||||||
|
resetToFirstParent.Click += (_, ev) =>
|
||||||
|
{
|
||||||
|
if (change.Index == Models.ChangeState.Renamed)
|
||||||
|
{
|
||||||
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.OriginalPath, $"{_commit.SHA}~1");
|
||||||
|
}
|
||||||
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}~1");
|
||||||
|
ev.Handled = true;
|
||||||
|
};
|
||||||
|
|
||||||
var copyPath = new MenuItem();
|
var copyPath = new MenuItem();
|
||||||
copyPath.Header = App.Text("CopyPath");
|
copyPath.Header = App.Text("CopyPath");
|
||||||
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
|
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
|
||||||
|
@ -340,7 +343,6 @@ namespace SourceGit.ViewModels
|
||||||
App.CopyText(change.Path);
|
App.CopyText(change.Path);
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
menu.Items.Add(copyPath);
|
|
||||||
|
|
||||||
var copyFileName = new MenuItem();
|
var copyFileName = new MenuItem();
|
||||||
copyFileName.Header = App.Text("CopyFileName");
|
copyFileName.Header = App.Text("CopyFileName");
|
||||||
|
@ -350,6 +352,11 @@ namespace SourceGit.ViewModels
|
||||||
App.CopyText(Path.GetFileName(change.Path));
|
App.CopyText(Path.GetFileName(change.Path));
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu.Items.Add(resetToThisRevision);
|
||||||
|
menu.Items.Add(resetToFirstParent);
|
||||||
|
menu.Items.Add(new MenuItem { Header = "-" });
|
||||||
|
menu.Items.Add(copyPath);
|
||||||
menu.Items.Add(copyFileName);
|
menu.Items.Add(copyFileName);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
|
@ -369,6 +376,18 @@ namespace SourceGit.ViewModels
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var resetToFirstParent = new MenuItem();
|
||||||
|
resetToFirstParent.Header = App.Text("ChangeCM.CheckoutFirstParentRevision");
|
||||||
|
resetToFirstParent.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
||||||
|
var fileInChanges = _changes.Find(x => x.Path == file.Path);
|
||||||
|
var fileIndex = fileInChanges?.Index;
|
||||||
|
resetToFirstParent.IsEnabled = _commit.Parents.Count > 0 && fileIndex != Models.ChangeState.Renamed;
|
||||||
|
resetToFirstParent.Click += (_, ev) =>
|
||||||
|
{
|
||||||
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(file.Path, $"{_commit.SHA}~1");
|
||||||
|
ev.Handled = true;
|
||||||
|
};
|
||||||
|
|
||||||
var explore = new MenuItem();
|
var explore = new MenuItem();
|
||||||
explore.Header = App.Text("RevealFile");
|
explore.Header = App.Text("RevealFile");
|
||||||
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
||||||
|
@ -448,6 +467,7 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
var menu = new ContextMenu();
|
var menu = new ContextMenu();
|
||||||
menu.Items.Add(resetToThisRevision);
|
menu.Items.Add(resetToThisRevision);
|
||||||
|
menu.Items.Add(resetToFirstParent);
|
||||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||||
menu.Items.Add(explore);
|
menu.Items.Add(explore);
|
||||||
menu.Items.Add(saveAs);
|
menu.Items.Add(saveAs);
|
||||||
|
|
Loading…
Reference in a new issue