Skip to content

Commit

Permalink
CloneVerb: Force download of commit and trees on failed initial checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickstolee committed Sep 28, 2018
1 parent 0465c34 commit f01f433
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 21 additions & 0 deletions GVFS/GVFS/CommandLine/CloneVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,27 @@ private Result CreateClone(
}

GitProcess.Result forceCheckoutResult = git.ForceCheckout(branch);
if (forceCheckoutResult.HasErrors)
{
// It is possible to have the above TryDownloadCommit() fail because we
// already have the commit and root tree we intend to check out, but
// don't have a tree further down the working directory. If we fail
// checkout here, it may be due to not having these trees and the
// read-object hook is not available yet. Force downloading the commit
// again and retry the checkout.

if (!this.ForceTryDownloadCommit(
refs.GetTipCommitId(branch),
objectRequestor,
gitObjects,
out errorMessage))
{
return new Result(errorMessage);
}

forceCheckoutResult = git.ForceCheckout(branch);
}

if (forceCheckoutResult.HasErrors)
{
string[] errorLines = forceCheckoutResult.Errors.Split('\n');
Expand Down
22 changes: 17 additions & 5 deletions GVFS/GVFS/CommandLine/GVFSVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,23 @@ protected bool TryDownloadCommit(
{
if (!repo.CommitAndRootTreeExists(commitId))
{
if (!gitObjects.TryDownloadCommit(commitId))
{
error = "Could not download commit " + commitId + " from: " + Uri.EscapeUriString(objectRequestor.CacheServer.ObjectsEndpointUrl);
return false;
}
return this.ForceTryDownloadCommit(commitId, objectRequestor, gitObjects, out error);
}

error = null;
return true;
}

protected bool ForceTryDownloadCommit(
string commitId,
GitObjectsHttpRequestor objectRequestor,
GVFSGitObjects gitObjects,
out string error)
{
if (!gitObjects.TryDownloadCommit(commitId))
{
error = "Could not download commit " + commitId + " from: " + Uri.EscapeUriString(objectRequestor.CacheServer.ObjectsEndpointUrl);
return false;
}

error = null;
Expand Down

0 comments on commit f01f433

Please sign in to comment.