fix(data): force English git output for locale-fragile stderr matches
RevParseHeadAsync and CommitAsync's identity-error detection match English-only substrings against git stderr. Under a non-English OS/git locale these silently fail to match, falling through to a generic error. Force LC_ALL=C and LANGUAGE=C on the git ProcessStartInfo so git always emits English output regardless of ambient locale.
This commit is contained in:
@@ -122,6 +122,61 @@ public class GitServiceBootstrapTests : IDisposable
|
||||
Assert.Equal("ClaudeDo <claudedo@local>", author);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RevParseHead_EmptyRepo_FriendlyMessage_EvenUnderNonEnglishLocale()
|
||||
{
|
||||
if (!GitAvailable) { Assert.True(true, "git not available -- skipping"); return; }
|
||||
|
||||
var dir = InitEmptyRepo();
|
||||
var previousLanguage = Environment.GetEnvironmentVariable("LANGUAGE");
|
||||
var previousLcAll = Environment.GetEnvironmentVariable("LC_ALL");
|
||||
// Simulate a non-English OS/git locale on the *ambient* process environment.
|
||||
// GitService must override it per-call so its English-only stderr matches
|
||||
// (e.g. "ambiguous argument 'HEAD'") keep working regardless.
|
||||
Environment.SetEnvironmentVariable("LANGUAGE", "de");
|
||||
Environment.SetEnvironmentVariable("LC_ALL", "de_DE.UTF-8");
|
||||
try
|
||||
{
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _git.RevParseHeadAsync(dir));
|
||||
Assert.Contains("no commits yet", ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("LANGUAGE", previousLanguage);
|
||||
Environment.SetEnvironmentVariable("LC_ALL", previousLcAll);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CommitAsync_MissingIdentity_FallsBackToClaudeDoIdentity_EvenUnderNonEnglishLocale()
|
||||
{
|
||||
if (!GitAvailable) { Assert.True(true, "git not available -- skipping"); return; }
|
||||
|
||||
var dir = InitEmptyRepo();
|
||||
GitRepoFixture.RunGit(dir, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "--allow-empty", "-m", "seed");
|
||||
GitRepoFixture.RunGit(dir, "config", "user.name", "");
|
||||
GitRepoFixture.RunGit(dir, "config", "user.email", "");
|
||||
File.WriteAllText(Path.Combine(dir, "work.txt"), "content\n");
|
||||
await _git.AddAllAsync(dir);
|
||||
|
||||
var previousLanguage = Environment.GetEnvironmentVariable("LANGUAGE");
|
||||
var previousLcAll = Environment.GetEnvironmentVariable("LC_ALL");
|
||||
Environment.SetEnvironmentVariable("LANGUAGE", "de");
|
||||
Environment.SetEnvironmentVariable("LC_ALL", "de_DE.UTF-8");
|
||||
try
|
||||
{
|
||||
await _git.CommitAsync(dir, "feat(test): identity fallback under non-English locale");
|
||||
|
||||
var author = GitRepoFixture.RunGit(dir, "log", "-1", "--format=%an <%ae>").Trim();
|
||||
Assert.Equal("ClaudeDo <claudedo@local>", author);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("LANGUAGE", previousLanguage);
|
||||
Environment.SetEnvironmentVariable("LC_ALL", previousLcAll);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var dir in _tempDirs)
|
||||
|
||||
Reference in New Issue
Block a user