Skip to content
Closed
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
25 changes: 25 additions & 0 deletions GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/CloneTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@ public void CloneCreatesCorrectFilesInRoot()
}
}

[TestCase]
public void CloneWithNonExistentBranchFailsWithBranchError()
{
string newEnlistmentRoot = GVFSFunctionalTestEnlistment.GetUniqueEnlistmentRoot();

ProcessStartInfo processInfo = new ProcessStartInfo(GVFSTestConfig.PathToGVFS);
processInfo.Arguments = $"clone {GVFSTestConfig.RepoToClone} {newEnlistmentRoot} --branch nonexistent/branch/that/does/not/exist";
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
processInfo.CreateNoWindow = true;
processInfo.WorkingDirectory = Path.GetDirectoryName(this.Enlistment.EnlistmentRoot);
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;

ProcessResult result = ProcessHelper.Run(processInfo);
result.ExitCode.ShouldEqual(GVFSGenericError);

// The clone should surface the real, actionable failure...
result.Output.ShouldContain("Remote branch nonexistent/branch/that/does/not/exist not found in upstream origin");

// ...and NOT the misleading downstream exception that used to be thrown when
// a LibGit2RepoInvoker was constructed against a src folder that was never created.
result.Output.ShouldNotContain(false, "Couldn't open repo");
result.Output.ShouldNotContain(false, "InvalidDataException");
}

private void SubfolderCloneShouldFail()
{
ProcessStartInfo processInfo = new ProcessStartInfo(GVFSTestConfig.PathToGVFS);
Expand Down
15 changes: 11 additions & 4 deletions GVFS/GVFS/CommandLine/CloneVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public override void Execute()

CacheServerInfo cacheServer = null;
ServerGVFSConfig serverGVFSConfig = null;
bool trustPackIndexes;
bool trustPackIndexes = false;

using (JsonTracer tracer = new JsonTracer(GVFSConstants.GVFSEtwProviderName, "GVFSClone"))
{
Expand Down Expand Up @@ -248,10 +248,17 @@ public override void Execute()
{
tracer.RelatedError(cloneResult.ErrorMessage);
}

using (var repo = new LibGit2RepoInvoker(tracer, enlistment.WorkingDirectoryBackingRoot))
else
{
trustPackIndexes = repo.GetConfigBoolOrDefault(GVFSConstants.GitConfig.TrustPackIndexes, GVFSConstants.GitConfig.TrustPackIndexesDefault);
// Only inspect the freshly-cloned repo when the clone succeeded. On a failed
// clone the 'src' working directory was never created, so constructing a
// LibGit2RepoInvoker here would log a misleading "Couldn't open repo" warning
// and throw an InvalidDataException that masks the real failure (e.g. the
// "Remote branch ... not found in upstream origin" error surfaced below).
using (var repo = new LibGit2RepoInvoker(tracer, enlistment.WorkingDirectoryBackingRoot))
{
trustPackIndexes = repo.GetConfigBoolOrDefault(GVFSConstants.GitConfig.TrustPackIndexes, GVFSConstants.GitConfig.TrustPackIndexesDefault);
}
}
}

Expand Down
Loading