Skip to content

Commit

Permalink
add option to use UTF-8 file names (requires Git 1.7.10+)
Browse files Browse the repository at this point in the history
  • Loading branch information
yysun committed May 15, 2012
1 parent 48843ec commit c9fd2de
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 13 deletions.
36 changes: 25 additions & 11 deletions BasicSccProvider.Tests/GitFileStatusTrackerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void GetFileStatusTest()
tracker.Refresh();
Assert.AreEqual(GitFileStatus.Added, tracker.GetFileStatus(tempFile));

tracker.Commit("test commit");
tracker.Commit("中文 1čtestč");
Assert.AreEqual(GitFileStatus.Tracked, tracker.GetFileStatus(tempFile));

File.WriteAllText(tempFile, "changed text");
Expand Down Expand Up @@ -151,7 +151,7 @@ public void GetFileContentTest()

GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
tracker.StageFile(tempFile);
tracker.Commit("test");
tracker.Commit("中文 1čtestč");

var fileContent = tracker.GetFileContent(tempFile);

Expand Down Expand Up @@ -184,7 +184,7 @@ public void GetFileContentTestNegative()
fileContent = tracker.GetFileContent(tempFile + ".bad");
Assert.IsNull(fileContent);

tracker.Commit("test");
tracker.Commit("中文 1čtestč");

fileContent = tracker.GetFileContent(tempFile + ".bad");
Assert.IsNull(fileContent);
Expand All @@ -203,7 +203,7 @@ public void GetChangedFilesTest()
tracker.StageFile(tempFile);
Assert.AreEqual(GitFileStatus.Added, tracker.ChangedFiles.ToList()[0].Status);

tracker.Commit("test");
tracker.Commit("中文 1čtestč");

Assert.AreEqual(0, tracker.ChangedFiles.Count());

Expand All @@ -223,9 +223,9 @@ public void LastCommitMessageTest()

GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
tracker.StageFile(tempFile);
tracker.Commit("test message");
Assert.IsTrue(tracker.LastCommitMessage.StartsWith("test message"));

tracker.Commit("中文 1čtestč");
Assert.IsTrue(tracker.LastCommitMessage.StartsWith("中文 1čtestč"));
}

[TestMethod]
Expand All @@ -237,8 +237,8 @@ public void AmendCommitTest()
GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
tracker.StageFile(tempFile);

tracker.Commit("test message");
Assert.IsTrue(tracker.LastCommitMessage.StartsWith("test message"));
tracker.Commit("中文 1čtestč");
Assert.IsTrue(tracker.LastCommitMessage.StartsWith("中文 1čtestč"));

File.WriteAllText(tempFile, "changed text");
tracker.StageFile(tempFile);
Expand Down Expand Up @@ -351,6 +351,19 @@ public GitFileStatusTrackerTest_NonAsciiFile()
}
}

[TestClass()]
public class GitFileStatusTrackerTest_NonAsciiFile_GitBash : GitFileStatusTrackerTest
{
public GitFileStatusTrackerTest_NonAsciiFile_GitBash()
{
GitBash.GitExePath = @"C:\Program Files (x86)\Git\bin\sh.exe";
GitBash.UseUTF8FileNames = true;
tempFolder = Environment.CurrentDirectory + "\\" + Guid.NewGuid().ToString();
Directory.CreateDirectory(tempFolder);
tempFile = Path.Combine(tempFolder, "中文 1čtestč");
}
}

[TestClass()]
public class GitFileStatusTrackerTest_WithSubFolder : GitFileStatusTrackerTest
{
Expand Down Expand Up @@ -380,9 +393,10 @@ public class GitFileStatusTrackerTest_WithSubFolder_UsingGitBash : GitFileStatus
public GitFileStatusTrackerTest_WithSubFolder_UsingGitBash()
{
GitBash.GitExePath = @"C:\Program Files (x86)\Git\bin\sh.exe";
GitBash.UseUTF8FileNames = true;
tempFolder = Environment.CurrentDirectory + "\\" + Guid.NewGuid().ToString();
Directory.CreateDirectory(Path.Combine(tempFolder, "folder 2"));
tempFile = Path.Combine(tempFolder, "folder 2\\t e s t");
Directory.CreateDirectory(Path.Combine(tempFolder, "folder 1\\中文 1čtestč"));
tempFile = Path.Combine(tempFolder, "folder 1\\中文 1čtestč\\中文 1čtestč");
}
}
}
1 change: 1 addition & 0 deletions BasicSccProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public BasicSccProvider()
_SccProvider = this;
Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering constructor for: {0}", this.ToString()));
GitBash.GitExePath = GitSccOptions.Current.GitBashPath;
GitBash.UseUTF8FileNames = GitSccOptions.Current.UseUTF8FileNames;
}

/////////////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 12 additions & 1 deletion GitApi/GitBash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace GitScc
{
public abstract class GitBash
{
public static bool UseUTF8FileNames { get; set; }

private static string gitExePath;
public static string GitExePath
{
Expand Down Expand Up @@ -44,6 +46,12 @@ public static string Run(string args, string workingDirectory)
WorkingDirectory = workingDirectory,
};

if (UseUTF8FileNames)
{
pinfo.StandardOutputEncoding = Encoding.UTF8;
pinfo.StandardErrorEncoding = Encoding.UTF8;
}

using (var process = Process.Start(pinfo))
{
string output = process.StandardOutput.ReadToEnd();
Expand Down Expand Up @@ -78,7 +86,10 @@ public static void RunCmd(string args, string workingDirectory)
UseShellExecute = false,
WorkingDirectory = workingDirectory,
};

if (UseUTF8FileNames)
{
pinfo.StandardErrorEncoding = Encoding.UTF8;
}
using (var process = Process.Start(pinfo))
{
string error = process.StandardError.ReadToEnd();
Expand Down
7 changes: 7 additions & 0 deletions GitApi/GitFileStatusTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,14 @@ public string Commit(string message)
if (GitBash.Exists)
{
var msgFile = Path.Combine(this.repository.Directory, "COMMITMESSAGE");

File.WriteAllText(msgFile, message);

//using (var textWriter = new StreamWriter(msgFile, false, GetCommentEncoding()))
//{
// textWriter.Write(message);
//}

msg = GitBash.Run(string.Format("commit -F \"{0}\"", msgFile), this.GitWorkingDirectory);
if (msg.IndexOf('\n') > 0) msg = msg.Split('\n')[0];
File.Delete(msgFile);
Expand Down
1 change: 1 addition & 0 deletions GitSccOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class GitSccOptions
public bool UseTGitIconSet { get; set; }
public bool DisableAutoRefresh { get; set; }
public bool DisableAutoLoad { get; set; }
public bool UseUTF8FileNames { get; set; }

private static GitSccOptions gitSccOptions;

Expand Down
1 change: 1 addition & 0 deletions GitUI/GitSccOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class GitSccOptions
public bool UseTGitIconSet { get; set; }
public bool DisableAutoRefresh { get; set; }
public bool DisableAutoLoad { get; set; }
public bool UseUTF8FileNames { get; set; }

private static GitSccOptions gitSccOptions;

Expand Down
1 change: 1 addition & 0 deletions GitUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
this.Style = (Style)Resources["GradientStyle"];

GitBash.GitExePath = GitSccOptions.Current.GitBashPath;
GitBash.UseUTF8FileNames = GitSccOptions.Current.UseUTF8FileNames;

if (!GitBash.Exists) GitBash.GitExePath = TryFindFile(new string[] {
@"C:\Program Files\Git\bin\sh.exe",
Expand Down
19 changes: 18 additions & 1 deletion SccProviderOptionsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class SccProviderOptionsControl : System.Windows.Forms.UserControl
private CheckBox checkBox3;
private CheckBox checkBox4;
private CheckBox checkBox5;
private CheckBox checkBox6;
// The parent page, use to persist data
private SccProviderOptions _customPage;

Expand Down Expand Up @@ -104,6 +105,7 @@ private void InitializeComponent()
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.checkBox4 = new System.Windows.Forms.CheckBox();
this.checkBox5 = new System.Windows.Forms.CheckBox();
this.checkBox6 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// openFileDialog1
Expand Down Expand Up @@ -260,18 +262,30 @@ private void InitializeComponent()
//
this.checkBox5.AutoSize = true;
this.checkBox5.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.checkBox5.Location = new System.Drawing.Point(6, 296);
this.checkBox5.Location = new System.Drawing.Point(6, 289);
this.checkBox5.Name = "checkBox5";
this.checkBox5.Size = new System.Drawing.Size(303, 17);
this.checkBox5.TabIndex = 27;
this.checkBox5.Text = "Disable auto switch to this plug-in for Git controlled projects";
this.checkBox5.UseVisualStyleBackColor = true;
//
// checkBox6
//
this.checkBox6.AutoSize = true;
this.checkBox6.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.checkBox6.Location = new System.Drawing.Point(6, 313);
this.checkBox6.Name = "checkBox6";
this.checkBox6.Size = new System.Drawing.Size(229, 17);
this.checkBox6.TabIndex = 28;
this.checkBox6.Text = "Use UTF-8 file names (requires Git 1.7.10+)";
this.checkBox6.UseVisualStyleBackColor = true;
//
// SccProviderOptionsControl
//
this.AllowDrop = true;
this.AutoScroll = true;
this.AutoSize = true;
this.Controls.Add(this.checkBox6);
this.Controls.Add(this.checkBox5);
this.Controls.Add(this.checkBox4);
this.Controls.Add(this.checkBox3);
Expand Down Expand Up @@ -317,6 +331,7 @@ private void SccProviderOptionsControl_Load(object sender, EventArgs e)
this.checkBox3.Checked = GitSccOptions.Current.UseTGitIconSet;
this.checkBox4.Checked = GitSccOptions.Current.DisableAutoRefresh;
this.checkBox5.Checked = GitSccOptions.Current.DisableAutoLoad;
this.checkBox6.Checked = GitSccOptions.Current.UseUTF8FileNames;
}

private void button1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -360,6 +375,8 @@ internal void Save()
GitSccOptions.Current.UseTGitIconSet = this.checkBox3.Checked;
GitSccOptions.Current.DisableAutoRefresh = this.checkBox4.Checked;
GitSccOptions.Current.DisableAutoLoad = this.checkBox5.Checked;
GitBash.UseUTF8FileNames =
GitSccOptions.Current.UseUTF8FileNames = this.checkBox6.Checked;
GitSccOptions.Current.SaveConfig();

SccProviderService sccProviderService = (SccProviderService)GetService(typeof(SccProviderService));
Expand Down

0 comments on commit c9fd2de

Please sign in to comment.