Browse Source

Handle exception if `git` is not found

pull/1915/head
duckdoom5 4 months ago
parent
commit
307f720ef5
  1. 77
      src/Generator/Utils/Utils.cs

77
src/Generator/Utils/Utils.cs

@ -84,7 +84,7 @@ namespace CppSharp @@ -84,7 +84,7 @@ namespace CppSharp
{
while (stringBuilder.Length > 0 && stringBuilder[0] == '_')
stringBuilder.Remove(0, 1);
while (stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] == '_')
while (stringBuilder.Length > 0 && stringBuilder[^1] == '_')
stringBuilder.Remove(stringBuilder.Length - 1, 1);
}
}
@ -136,47 +136,54 @@ namespace CppSharp @@ -136,47 +136,54 @@ namespace CppSharp
{
public static NewLineType? GetNewLineTypeFromGitConfig(string outputDir)
{
if (!bool.TryParse(
ProcessHelper.RunFrom(outputDir,
"git", "rev-parse --is-inside-work-tree",
out _, out _
),
out bool isInsideWorkTree))
try
{
return null;
}
if (!bool.TryParse(
ProcessHelper.RunFrom(outputDir,
"git", "rev-parse --is-inside-work-tree",
out _, out _
),
out bool isInsideWorkTree))
{
return null;
}
if (!isInsideWorkTree)
return null;
if (!isInsideWorkTree)
return null;
// Check git config core.eol setting
var eolConfig = ProcessHelper.RunFrom(outputDir,
"git", "config --get core.eol",
out _, out _)
.Trim().ToLowerInvariant();
// Check git config core.eol setting
var eolConfig = ProcessHelper.RunFrom(outputDir,
"git", "config --get core.eol",
out _, out _)
.Trim().ToLowerInvariant();
switch (eolConfig)
{
case "lf":
return NewLineType.LF;
case "crlf":
return NewLineType.CRLF;
}
switch (eolConfig)
{
case "lf":
return NewLineType.LF;
case "crlf":
return NewLineType.CRLF;
}
// Otherwise check git config core.autocrlf setting
var autoCrLf = ProcessHelper.RunFrom(outputDir,
"git", "config --get core.autocrlf",
out _, out _)
.Trim().ToLowerInvariant();
// Otherwise check git config core.autocrlf setting
var autoCrLf = ProcessHelper.RunFrom(outputDir,
"git", "config --get core.autocrlf",
out _, out _)
.Trim().ToLowerInvariant();
return autoCrLf switch
{
"input" => NewLineType.LF,
"true" => NewLineType.CRLF,
"false" => NewLineType.Host,
return autoCrLf switch
{
"input" => NewLineType.LF,
"true" => NewLineType.CRLF,
"false" => NewLineType.Host,
_ => null
};
_ => null
};
}
catch (Exception)
{
return null;
}
}
}
}

Loading…
Cancel
Save