Skip to content

Commit

Permalink
CheckGitVersion: improve error messages
Browse files Browse the repository at this point in the history
A user reported issues with parsing our Git version when cloning. Our
best guess of what happened is that the build machine already had a
version of Git, but it was in a different location whan where our `brew`
formula placed our version of Git. This led the parser to not see a
`.vfs.` in the version string and fail.

Let's make this error more informative. While we are here, split the
failure condition into two distinct cases:

1. We can't find Git anywhere.
2. We can't parse the Git version.

Add the GitBinPath to the other error messages in this method.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Jul 13, 2020
1 parent 0abeba4 commit 0aef28c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Scalar/CommandLine/ScalarVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,24 +492,30 @@ private string GetAlternatesPath(ScalarEnlistment enlistment)
private void CheckGitVersion(ITracer tracer, ScalarEnlistment enlistment, out string version)
{
GitVersion gitVersion = null;
if (string.IsNullOrEmpty(enlistment.GitBinPath) || !GitProcess.TryGetVersion(enlistment.GitBinPath, out gitVersion, out string _))
if (string.IsNullOrEmpty(enlistment.GitBinPath))
{
this.ReportErrorAndExit(tracer, "Error: Unable to retrieve the git version");
this.ReportErrorAndExit(tracer, "Unable to find Git version on PATH");
}

if (!GitProcess.TryGetVersion(enlistment.GitBinPath, out gitVersion, out string error))
{
this.ReportErrorAndExit(tracer, $"Unable to parse Git version at '{enlistment.GitBinPath}':\n{error}");
}

version = gitVersion.ToString();

if (gitVersion.Platform != ScalarConstants.SupportedGitVersion.Platform)
{
this.ReportErrorAndExit(tracer, "Error: Invalid version of git {0}. Must use scalar version.", version);
this.ReportErrorAndExit(tracer, "Error: Invalid version of git {0} at {1}. Must use scalar version.", version, enlistment.GitBinPath);
}

if (gitVersion.IsLessThan(ScalarConstants.SupportedGitVersion))
{
this.ReportErrorAndExit(
tracer,
"Error: Installed git version {0} is less than the supported version of {1}.",
"Error: Installed git version {0} at {1} is less than the supported version of {2}.",
gitVersion,
enlistment.GitBinPath,
ScalarConstants.SupportedGitVersion);
}
}
Expand Down

0 comments on commit 0aef28c

Please sign in to comment.