repo git: Make restore from history work on all storage types

This commit is contained in:
Hylke Bons 2016-06-20 13:24:59 -07:00 committed by Hylke Bons
parent 6716f1dcce
commit 3a98e968c3

View file

@ -650,42 +650,26 @@ namespace Sparkles.Git {
Logger.LogInfo ("Git", Name + " | Restoring \"" + path + "\" (revision " + revision + ")"); Logger.LogInfo ("Git", Name + " | Restoring \"" + path + "\" (revision " + revision + ")");
// git-show doesn't decrypt objects, so we can't use it to retrieve // Restore the older file...
// files from the index. This is a suboptimal workaround but it does the job var git = new GitCommand (LocalPath, "checkout " + revision + " \"" + path + "\"");
if (StorageType == StorageType.Encrypted) { git.StartAndWaitForExit ();
// Restore the older file...
var git = new GitCommand (LocalPath, "checkout " + revision + " \"" + path + "\"");
git.StartAndWaitForExit ();
string local_file_path = Path.Combine (LocalPath, path); string local_file_path = Path.Combine (LocalPath, path);
// ...move it... // ...move it...
try { try {
File.Move (local_file_path, target_file_path); File.Move (local_file_path, target_file_path);
} catch {
Logger.LogInfo ("Git",
Name + " | Could not move \"" + local_file_path + "\" to \"" + target_file_path + "\"");
}
// ...and restore the most recent revision
git = new GitCommand (LocalPath, "checkout " + CurrentRevision + " \"" + path + "\"");
git.StartAndWaitForExit ();
// The correct way } catch {
} else { Logger.LogInfo ("Git",
path = path.Replace ("\"", "\\\""); Name + " | Could not move \"" + local_file_path + "\" to \"" + target_file_path + "\"");
var git = new GitCommand (LocalPath, "show " + revision + ":\"" + path + "\"");
git.Start ();
FileStream stream = File.OpenWrite (target_file_path);
git.StandardOutput.BaseStream.CopyTo (stream);
stream.Close ();
git.WaitForExit ();
} }
// ...and restore the most recent revision
git = new GitCommand (LocalPath, "checkout " + CurrentRevision + " \"" + path + "\"");
git.StartAndWaitForExit ();
if (target_file_path.StartsWith (LocalPath)) if (target_file_path.StartsWith (LocalPath))
new Thread (() => OnFileActivity (null)).Start (); new Thread (() => OnFileActivity (null)).Start ();
} }