Skip to content
Browse files

save file and checkout file using git.exe

  • Loading branch information...
1 parent b01c2d1 commit 27ce6adac9c5c28d1f65fb92dbc393b6d7d7d8b7 @yysun committed Nov 28, 2011
Showing with 60 additions and 17 deletions.
  1. +41 −0 GitFileStatusTracker.cs
  2. +19 −17 SccProviderService.cs
View
41 GitFileStatusTracker.cs
@@ -1045,6 +1045,47 @@ public IList<GitFile> ParseGitStatus(string statusString)
}
#endregion
+
+ internal void SaveFileFromRepository(string fileName, string tempFile)
+ {
+ if (!this.HasGitRepository || this.head == null) return;
+
+ string fileNameRel = GetRelativeFileName(fileName);
+
+ if (GitBash.Exists)
+ {
+ GitBash.RunCmd(string.Format("show HEAD:{0} > \"{1}\"", fileNameRel, tempFile), this.GitWorkingDirectory);
+ }
+ else
+ {
+ var data = GetFileContent(fileName);
+ using (var binWriter = new BinaryWriter(File.Open(tempFile, System.IO.FileMode.Create)))
+ {
+ binWriter.Write(data ?? new byte[] { });
+ }
+ }
+ }
+
+ internal void CheckOutFile(string fileName)
+ {
+ if (!this.HasGitRepository || this.head == null) return;
+
+ string fileNameRel = GetRelativeFileName(fileName);
+
+ if (GitBash.Exists)
+ {
+ GitBash.Run("checkout -- " + fileNameRel, this.GitWorkingDirectory);
+ }
+ else
+ {
+ GitFileStatus status = GetFileStatus(fileName);
+ SaveFileFromRepository(fileName, fileName);
+ if (status == GitFileStatus.Staged || status == GitFileStatus.Removed)
+ {
+ UnStageFile(fileName);
+ }
+ }
+ }
}
public abstract class Log
View
36 SccProviderService.cs
@@ -718,7 +718,7 @@ internal void CompareFile(string fileName)
{
string tempFile = Path.GetFileName(fileName);
tempFile = Path.Combine(Path.GetTempPath(), tempFile);
- SaveFileFromRepository(fileName, tempFile);
+ CurrentTracker.SaveFileFromRepository(fileName, tempFile);
_sccProvider.RunDiffCommand(tempFile, fileName);
}
}
@@ -747,11 +747,13 @@ internal void UndoFileChanges(string fileName)
" and store it from last commit? " + deleteMsg,
"Undo Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
- SaveFileFromRepository(fileName, fileName);
- if (status == GitFileStatus.Staged || status == GitFileStatus.Removed)
- {
- CurrentTracker.UnStageFile(fileName);
- }
+ //SaveFileFromRepository(fileName, fileName);
+ //if (status == GitFileStatus.Staged || status == GitFileStatus.Removed)
+ //{
+ // CurrentTracker.UnStageFile(fileName);
+ //}
+
+ CurrentTracker.CheckOutFile(fileName);
}
}
}
@@ -906,16 +908,16 @@ private GitFileStatus GetFileStatus(IVsHierarchy phierHierarchy, uint itemidNode
return GetFileStatus(fileName);
}
- private void SaveFileFromRepository(string fileName, string tempFile)
- {
- var tracker = CurrentTracker;
- if (tracker == null) return;
- var data = tracker.GetFileContent(fileName);
- using (var binWriter = new BinaryWriter(File.Open(tempFile, FileMode.Create)))
- {
- binWriter.Write(data ?? new byte[] { });
- }
- }
+ //private void SaveFileFromRepository(string fileName, string tempFile)
+ //{
+ // var tracker = CurrentTracker;
+ // if (tracker == null) return;
+ // var data = tracker.GetFileContent(fileName);
+ // using (var binWriter = new BinaryWriter(File.Open(tempFile, FileMode.Create)))
+ // {
+ // binWriter.Write(data ?? new byte[] { });
+ // }
+ //}
#endregion
#region new Refresh methods
@@ -933,9 +935,9 @@ internal void Refresh()
{
Debug.WriteLine("==== Refresh: " + Math.Floor(delta).ToString());
NodesGlyphsDirty = true;
+ lastTimeRefresh = DateTime.Now;
}
}
- lastTimeRefresh = DateTime.Now;
}
public void UpdateNodesGlyphs()

0 comments on commit 27ce6ad

Please sign in to comment.
Something went wrong with that request. Please try again.