Skip to content

Commit

Permalink
Merge pull request #92: Always use read-object hook during checkout
Browse files Browse the repository at this point in the history
While refactoring the `CloneVerb` in #77, I moved the `git checkout -f` command to the end of clone, as needed. This is because we will actually fill out blobs during this initial checkout.

However, there was one slight problem: we need the read-object hook. There are two ways to do a checkout in the `GitProcess`, and one was not allowing the read-object hook.

Before #77, this checkout was called before the mount was ready, but that's no longer important.

Thanks @jamill for finding this bug!
  • Loading branch information
derrickstolee authored Aug 28, 2019
2 parents fd9d4cf + 85615a5 commit bdd2a24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Scalar.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public Result CreateBranchWithUpstream(string branchToCreate, string upstreamBra

public Result ForceCheckout(string target)
{
return this.InvokeGitInWorkingDirectoryRoot("checkout -f " + target, useReadObjectHook: false);
return this.InvokeGitInWorkingDirectoryRoot("checkout -f " + target, useReadObjectHook: true);
}

public Result ForceCheckoutAllFiles()
Expand Down
18 changes: 18 additions & 0 deletions Scalar.FunctionalTests/Tests/EnlistmentPerFixture/CloneTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ public void CloneWithLocalCachePathWithinSrc()
result.Output.ShouldContain("'--local-cache-path' cannot be inside the src folder");
}

[TestCase]
public void SparseCloneWithNoPrefetchSucceeds()
{
ScalarFunctionalTestEnlistment enlistment = null;

try
{
enlistment = ScalarFunctionalTestEnlistment.CloneAndMountWithPerRepoCache(ScalarTestConfig.PathToScalar, skipPrefetch: true);

ProcessResult result = GitProcess.InvokeProcess(enlistment.RepoRoot, "status");
result.ExitCode.ShouldEqual(0, result.Errors);
}
finally
{
enlistment?.UnmountAndDeleteAll();
}
}

[TestCase]
[Category(Categories.MacOnly)]
[Category(Categories.NeedsUpdatesForNonVirtualizedMode)]
Expand Down
7 changes: 6 additions & 1 deletion Scalar/CommandLine/CloneVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,13 @@ private Result CheckoutRepo()
}
}

if (this.git.ForceCheckout(this.Branch).ExitCodeIsFailure)
GitProcess.Result result = this.git.ForceCheckout(this.Branch);
if (result.ExitCodeIsFailure)
{
EventMetadata metadata = new EventMetadata();
metadata["git-output"] = result.Output;
metadata["git-errors"] = result.Errors;
this.tracer.RelatedError(metadata, "Failed to checkout repo");
return new Result("Failed to checkout repo");
}

Expand Down

0 comments on commit bdd2a24

Please sign in to comment.