Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion GVFS/GVFS.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ public static string ExpireTimeDateString

public static Result Init(Enlistment enlistment)
{
return new GitProcess(enlistment).InvokeGitOutsideEnlistment("init \"" + enlistment.WorkingDirectoryBackingRoot + "\"");
// --object-format=sha1 is pinned explicitly so that GVFS does not silently pick up
// a future git default of sha256. AzDO (the only GVFS-protocol server implementer)
// has no plans to support sha256, and GVFS's own code assumes 20-byte/40-hex-char
// sha1 object IDs throughout, so a sha256 repo would corrupt data or crash.
return enlistment.CreateGitProcess().InvokeGitOutsideEnlistment("init --object-format=sha1 \"" + enlistment.WorkingDirectoryBackingRoot + "\"");
}

public static ConfigResult GetFromGlobalConfig(string gitBinPath, string settingName)
Expand Down
19 changes: 19 additions & 0 deletions GVFS/GVFS.UnitTests/Git/GitProcessTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GVFS.Common.Git;
using GVFS.Tests.Should;
using GVFS.UnitTests.Mock.Common;
using GVFS.UnitTests.Mock.Git;
using NUnit.Framework;
using System.Diagnostics;

Expand All @@ -9,6 +10,24 @@ namespace GVFS.UnitTests.Git
[TestFixture]
public class GitProcessTests
{
[TestCase]
public void Init_PinsObjectFormatToSha1()
{
MockGitProcess gitProcess = new MockGitProcess();
MockGVFSEnlistment enlistment = new MockGVFSEnlistment(gitProcess);

string expectedCommand = "init --object-format=sha1 \"" + enlistment.WorkingDirectoryBackingRoot + "\"";
gitProcess.SetExpectedCommandResult(
expectedCommand,
() => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

GitProcess.Result result = GitProcess.Init(enlistment);

result.ExitCodeIsFailure.ShouldBeFalse();
gitProcess.CommandsRun.Count.ShouldEqual(1);
gitProcess.CommandsRun[0].ShouldEqual(expectedCommand);
}

[TestCase]
public void BoundedGitOutputBuffer_KeepsShortOutput()
{
Expand Down
Loading