Skip to content

Commit 11d3a24

Browse files
Merge pull request #374: Update Git to include en/sparse-checkout
Also fixes a bug when running `scalar clone` followed by `git sparse-checkout disable`. See microsoft/git#267.
2 parents 489764b + 356dbf5 commit 11d3a24

4 files changed

Lines changed: 24 additions & 47 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
VFS for Git (which is less flexible). Only update that version if we rely upon a
4444
new command-line interface in Git or if there is a truly broken interaction.
4545
-->
46-
<GitPackageVersion>2.20200420.2</GitPackageVersion>
46+
<GitPackageVersion>2.20200514.1</GitPackageVersion>
4747
<MinimumGitVersion>v2.25.0.vfs.1.1</MinimumGitVersion>
4848

4949
<WatchmanPackageUrl>https://github.com/facebook/watchman/suites/307436006/artifacts/304557</WatchmanPackageUrl>

Scalar.FunctionalTests/Tests/EnlistmentPerFixture/SparseSetTests.cs

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ namespace Scalar.FunctionalTests.Tests.EnlistmentPerFixture
1414
[Category(Categories.GitCommands)]
1515
public class SparseSetTests : TestsWithEnlistmentPerFixture
1616
{
17-
private const string SetOverwriteMessage = "would be overwritten by sparse checkout update";
17+
private const string SetOverwriteMessage = "The following paths were already present and thus not updated despite sparse patterns";
1818
private const string SetIndexStateMessage = "you need to resolve your current index first";
19+
private const string UnmergedPathsMessage = "The following paths are unmerged and were left despite sparse patterns";
1920

2021
private const string FolderDotGit = ".git";
2122
private const string FolderDeleteFileTests = "DeleteFileTests";
@@ -145,19 +146,11 @@ public void SparseSetFileAlreadyExists()
145146
// Contents before 'set'
146147
this.VerifyContentsForSparseSetFileAlreadyExists();
147148

148-
// If a file already exists that would conflict with a sparse checkout, the 'set' should fail
149+
// If a file already exists that would conflict with a sparse checkout, the 'set' will partially succeed.
149150
this.currentFolderList.Add(FolderEnumerateAndReadTestFiles);
150151
string result = this.SparseSet();
151152
result.ShouldContain(SetOverwriteMessage);
152153

153-
// Contents should be unchanged after failure
154-
this.VerifyContentsForSparseSetFileAlreadyExists();
155-
156-
// After deleting the conflicting file you should be able to 'set'
157-
this.fileSystem.DeleteFile(existingFile);
158-
result = this.SparseSet();
159-
result.ShouldNotContain(true, SetOverwriteMessage);
160-
161154
// Should now have multiple files under EnumerateAndReadTestFiles
162155
Directory.GetFiles(folderEnumerateDirectory).Length.ShouldEqual(18);
163156
}
@@ -231,15 +224,11 @@ public void SparseSetWithOneFolderConflict()
231224

232225
this.VerifyContentsSparseSetWithOneFolderConflict();
233226

234-
// One folder conflict should fail the entire 'set', and this does not modify the sparse-checkout file
235227
this.currentFolderList.Add(FolderTest_MoveRenameFileTests);
236228
this.currentFolderList.Add(FolderTest_MoveRenameFileTests2);
237229
string result = this.SparseSet();
238230
result.ShouldContain(SetOverwriteMessage);
239231

240-
// Results should be unchanged
241-
this.VerifyContentsSparseSetWithOneFolderConflict();
242-
243232
// Checkout new_branch
244233
GitProcess.Invoke(this.Enlistment.RepoRoot, "checkout -b new_branch");
245234

@@ -249,7 +238,7 @@ public void SparseSetWithOneFolderConflict()
249238

250239
this.fileSystem.DeleteFile(existingFile);
251240
result = this.SparseSet();
252-
result.ShouldNotContain(false, SetOverwriteMessage);
241+
result.ShouldBeEmpty();
253242

254243
// Verify the folders are now populated
255244
this.VerifyDirectory(folderRenameDirectory, new List<string>
@@ -269,9 +258,10 @@ public void SparseSetWithOneFolderConflict()
269258
[TestCase, Order(8)]
270259
public void AddWhileInMergeConflict()
271260
{
272-
// Attempt to 'set' while you have a cherry-pick merge conflict. It will say it failed.
261+
string result = this.SparseSet();
262+
263+
// Attempt to 'set' while you have a cherry-pick merge conflict. It will succeed.
273264
// Abort the cherry-pick, switch branches, and switch back. Now the folders will be fully populated.
274-
// The correct behavior should be that if the 'set' fails the folders should not be added to sparse
275265
string conflictFilename = "conflict";
276266
string fileToConflict = this.Enlistment.GetSourcePath(conflictFilename);
277267

@@ -292,29 +282,10 @@ public void AddWhileInMergeConflict()
292282
// Attempt to cherry-pick the commit we know will result in a merge conflict
293283
GitProcess.Invoke(this.Enlistment.RepoRoot, "cherry-pick " + commitId);
294284

295-
// Should not be able to add which we have a merge conflict
285+
// This should succeed!
296286
this.currentFolderList.Add(FolderTrailingSlashTests);
297-
string result = this.SparseSet();
298-
result.ShouldContain(SetIndexStateMessage);
299-
300-
// New directory should not be listed because of the error
301-
this.VerifyDirectory(this.Enlistment.RepoRoot, new List<string>
302-
{
303-
FolderDotGit,
304-
FolderEnumerateAndReadTestFiles,
305-
FolderFileNameEncoding,
306-
FolderGitCommandsTests,
307-
FolderGVFS,
308-
FolderScripts,
309-
FolderTest_MoveRenameFileTests,
310-
FolderTest_MoveRenameFileTests2
311-
});
312-
313-
// Fix the error, switch to the new branch, and switch back and we should have all directories
314-
GitProcess.Invoke(this.Enlistment.RepoRoot, "cherry-pick --abort");
315-
316287
result = this.SparseSet();
317-
result.ShouldNotContain(true, SetIndexStateMessage);
288+
result.ShouldContain(UnmergedPathsMessage);
318289

319290
GitProcess.Invoke(this.Enlistment.RepoRoot, "checkout branch_with_conflict");
320291
GitProcess.Invoke(this.Enlistment.RepoRoot, "checkout " + this.Enlistment.Commitish);
@@ -343,7 +314,8 @@ public void CherryPickWithChangesInAndOutOfTheCone()
343314

344315
// Add the folder with the commit out of the cone
345316
this.currentFolderList.Add(FolderTest_WorkingDirectoryTests);
346-
this.SparseSet();
317+
string result = this.SparseSet();
318+
result.ShouldContain(UnmergedPathsMessage);
347319

348320
// New Folder should exist
349321
string newFolder = this.Enlistment.GetSourcePath(FolderTest_WorkingDirectoryTests);
@@ -363,7 +335,8 @@ public void CherryPickWithChangesInAndOutOfTheCone()
363335

364336
// New changes should exist in the recently added file
365337
string fileWithCherryPick = Path.Combine(newFolder, "AllNullObjectRedownloaded.txt");
366-
this.fileSystem.ReadAllText(fileWithCherryPick).ShouldContain("TestTest contents for AllNullObjectRedownloaded");
338+
this.fileSystem.ReadAllText(fileWithCherryPick).ShouldContain("Test contents for AllNullObjectRedownloaded");
339+
GitProcess.Invoke(this.Enlistment.RepoRoot, "cherry-pick --abort");
367340
}
368341

369342
[TestCase, Order(10)]
@@ -377,6 +350,7 @@ public void MergeChangesOutOfTheConeWithConflict()
377350
string conflictTargetBranch = "FunctionalTests/20170206_Conflict_Target";
378351
GitProcess.Invoke(this.Enlistment.RepoRoot, $"checkout {conflictTargetBranch}");
379352
GitProcess.Invoke(this.Enlistment.RepoRoot, $"checkout {conflictSourceBranch}");
353+
380354
ProcessResult checkoutResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, $"merge {conflictTargetBranch}");
381355
checkoutResult.Output.ShouldContain("Merge conflict");
382356

@@ -511,9 +485,14 @@ private string SparseSet()
511485
sb.Append("\n");
512486
}
513487

488+
string lockfile = Path.Combine(this.Enlistment.RepoRoot, ".git", "info", "sparse-checkout.lock");
489+
this.fileSystem.FileExists(lockfile).ShouldBeFalse(message: $"{lockfile} exists");
490+
514491
ProcessResult result = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "sparse-checkout set --stdin", sb.ToString());
492+
result.ExitCode.ShouldEqual(0, $"Errors: {result.Errors}\nOutput: {result.Output}");
515493

516-
return result.Errors;
494+
this.fileSystem.FileExists(lockfile).ShouldBeFalse(message: $"{lockfile} exists");
495+
return result.Errors + result.Output;
517496
}
518497
}
519498
}

Scalar.FunctionalTests/Tests/GitCommands/GitRepoTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public virtual void SetupForTest()
143143
sb.Append("\n");
144144
}
145145

146+
GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, "sparse-checkout init --cone", string.Empty);
147+
GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, "sparse-checkout set --stdin", sb.ToString());
146148
GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "sparse-checkout set --stdin", sb.ToString());
147149
this.pathPrefixes = SparseModeFolders;
148150
}

Scalar/CommandLine/CloneVerb.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,7 @@ private Result GitClone()
329329

330330
if (!this.FullClone)
331331
{
332-
git.SetInLocalConfig($"core.sparseCheckout", "true");
333-
git.SetInLocalConfig($"core.sparseCheckoutCone", "true");
334-
335-
this.fileSystem.CreateDirectory(Path.Combine(this.enlistment.DotGitRoot, "info"));
336-
this.fileSystem.WriteAllText(Path.Combine(this.enlistment.DotGitRoot, "info", "sparse-checkout"), "/*\n!/*/*");
332+
GitProcess.SparseCheckoutInit(this.enlistment);
337333
}
338334

339335
this.context = new ScalarContext(this.tracer, this.fileSystem, this.enlistment);

0 commit comments

Comments
 (0)