mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
fix<CommitViewer>: fix save revision file to path error when selected file is managed by LFS
This commit is contained in:
parent
0e48344401
commit
db799f5c92
3 changed files with 37 additions and 29 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
@ -261,6 +262,39 @@ namespace SourceGit.Git {
|
|||
return string.Join("\n", data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save file to.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="saveTo"></param>
|
||||
public void SaveFileTo(Repository repo, string file, string saveTo) {
|
||||
var tmp = Path.GetTempFileName();
|
||||
var bat = tmp + ".bat";
|
||||
var cmd = "";
|
||||
|
||||
if (repo.IsLFSFiltered(file)) {
|
||||
cmd += $"git --no-pager show {SHA}:\"{file}\" > {tmp}.lfs\n";
|
||||
cmd += $"git --no-pager lfs smudge < {tmp}.lfs > {saveTo}\n";
|
||||
} else {
|
||||
cmd = $"git --no-pager show {SHA}:\"{file}\" > {saveTo}\n";
|
||||
}
|
||||
|
||||
File.WriteAllText(bat, cmd);
|
||||
|
||||
var starter = new ProcessStartInfo();
|
||||
starter.FileName = bat;
|
||||
starter.WorkingDirectory = repo.Path;
|
||||
starter.CreateNoWindow = true;
|
||||
starter.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
|
||||
var proc = Process.Start(starter);
|
||||
proc.WaitForExit();
|
||||
proc.Close();
|
||||
|
||||
File.Delete(bat);
|
||||
}
|
||||
|
||||
private static void ParseSHA(Commit commit, string data) {
|
||||
var decoratorStart = data.IndexOf('(');
|
||||
if (decoratorStart < 0) {
|
||||
|
|
|
@ -184,32 +184,6 @@ namespace SourceGit.Git {
|
|||
return RunCommand(Path, args, outputHandler, includeError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create process and redirect output to file.
|
||||
/// </summary>
|
||||
/// <param name="args">Git command arguments.</param>
|
||||
/// <param name="redirectTo">File path to redirect output into.</param>
|
||||
public void RunAndRedirect(string args, string redirectTo) {
|
||||
var startInfo = new ProcessStartInfo();
|
||||
startInfo.FileName = Preference.Instance.GitExecutable;
|
||||
startInfo.Arguments = "--no-pager " + args;
|
||||
startInfo.WorkingDirectory = Path;
|
||||
startInfo.UseShellExecute = false;
|
||||
startInfo.CreateNoWindow = true;
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
startInfo.RedirectStandardError = true;
|
||||
|
||||
var proc = new Process() { StartInfo = startInfo };
|
||||
proc.Start();
|
||||
|
||||
using (var writer = new FileStream(redirectTo, FileMode.OpenOrCreate)) {
|
||||
proc.StandardOutput.BaseStream.CopyTo(writer);
|
||||
}
|
||||
|
||||
proc.WaitForExit();
|
||||
proc.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assert command result and then update branches and commits.
|
||||
/// </summary>
|
||||
|
|
|
@ -298,12 +298,12 @@ namespace SourceGit.UI {
|
|||
saveAs.Header = "Save As ...";
|
||||
saveAs.Click += (obj, ev) => {
|
||||
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||
dialog.Description = change.Path;
|
||||
dialog.Description = path;
|
||||
dialog.ShowNewFolderButton = true;
|
||||
|
||||
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
|
||||
var savePath = Path.Combine(dialog.SelectedPath, Path.GetFileName(path));
|
||||
repo.RunAndRedirect($"show {commit.SHA}:\"{path}\"", savePath);
|
||||
commit.SaveFileTo(repo, path, savePath);
|
||||
}
|
||||
};
|
||||
menu.Items.Add(saveAs);
|
||||
|
@ -526,7 +526,7 @@ namespace SourceGit.UI {
|
|||
|
||||
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
|
||||
var path = Path.Combine(dialog.SelectedPath, node.Name);
|
||||
repo.RunAndRedirect($"show {commit.SHA}:\"{node.FilePath}\"", path);
|
||||
commit.SaveFileTo(repo, node.FilePath, path);
|
||||
}
|
||||
};
|
||||
menu.Items.Add(saveAs);
|
||||
|
|
Loading…
Reference in a new issue