Skip to content

Commit a763194

Browse files
author
Tomas Urbonaitis
committed
Throwing InvalidRepoExcpetion, when ssl-related bool git config keys have non-bool values. Handling InvalidRepoException in CloneVerb.
1 parent 3915d47 commit a763194

2 files changed

Lines changed: 39 additions & 18 deletions

File tree

GVFS/GVFS.Common/Git/GitSsl.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@ public GitSsl(IDictionary<string, GitConfigSetting> configSettings) : this()
3434
this.certificatePathOrSubjectCommonName = sslCerts.Values.Last();
3535
}
3636

37-
if (configSettings.TryGetValue(GitConfigSetting.HttpSslCertPasswordProtected, out GitConfigSetting isSslCertPasswordProtected))
38-
{
39-
this.isCertificatePasswordProtected = isSslCertPasswordProtected.Values.Select(bool.Parse).Last();
40-
}
37+
this.isCertificatePasswordProtected = SetBoolSettingOrThrow(configSettings, GitConfigSetting.HttpSslCertPasswordProtected, this.isCertificatePasswordProtected);
4138

42-
if (configSettings.TryGetValue(GitConfigSetting.HttpSslVerify, out GitConfigSetting sslVerify))
43-
{
44-
this.ShouldVerify = sslVerify.Values.Select(bool.Parse).Last();
45-
}
39+
this.ShouldVerify = SetBoolSettingOrThrow(configSettings, GitConfigSetting.HttpSslVerify, this.ShouldVerify);
4640
}
4741
}
4842

@@ -76,6 +70,23 @@ public X509Certificate2 GetCertificate(ITracer tracer, GitProcess gitProcess)
7670
}
7771

7872
return result;
73+
}
74+
75+
private static bool SetBoolSettingOrThrow(IDictionary<string, GitConfigSetting> configSettings, string settingName, bool currentValue)
76+
{
77+
if (configSettings.TryGetValue(settingName, out GitConfigSetting settingValues))
78+
{
79+
try
80+
{
81+
return settingValues.Values.Select(bool.Parse).Last();
82+
}
83+
catch (FormatException)
84+
{
85+
throw new InvalidRepoException($"{settingName} git setting did not have a bool-parsable value. Found: {string.Join(" ", settingValues.Values)}");
86+
}
87+
}
88+
89+
return currentValue;
7990
}
8091

8192
private static void LogWithAppropriateLevel(ITracer tracer, EventMetadata metadata, IEnumerable<X509Certificate2> certificates, string logMessage)

GVFS/GVFS/CommandLine/CloneVerb.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,22 @@ private Result TryCreateEnlistment(
301301

302302
string hooksPath = this.GetGVFSHooksPathAndCheckVersion(tracer: null, hooksVersion: out _);
303303

304-
enlistment = new GVFSEnlistment(
305-
normalizedEnlistementRootPath,
306-
this.RepositoryURL,
307-
gitBinPath,
308-
hooksPath,
309-
authentication: null);
304+
try
305+
{
306+
enlistment = new GVFSEnlistment(
307+
normalizedEnlistementRootPath,
308+
this.RepositoryURL,
309+
gitBinPath,
310+
hooksPath,
311+
authentication: null);
312+
}
313+
catch (InvalidRepoException e)
314+
{
315+
this.ReportErrorAndExit(
316+
"Error when creating a new GVFS enlistment at '{0}'. {1}",
317+
normalizedEnlistementRootPath,
318+
e.Message);
319+
}
310320

311321
return new Result(true);
312322
}
@@ -654,10 +664,10 @@ private void CreateGitScript(GVFSEnlistment enlistment)
654664
@"
655665
@echo OFF
656666
echo .
657-
echo ^[105;30m
658-
echo This repo was cloned using GVFS, and the git repo is in the 'src' directory
659-
echo Switching you to the 'src' directory and rerunning your git command
660-
echo [0m
667+
echo ^[105;30m
668+
echo This repo was cloned using GVFS, and the git repo is in the 'src' directory
669+
echo Switching you to the 'src' directory and rerunning your git command
670+
echo [0m
661671
662672
@echo ON
663673
cd src

0 commit comments

Comments
 (0)