Skip to content

Commit 666bd37

Browse files
committed
enable nullable for solution
1 parent 12e23f7 commit 666bd37

File tree

193 files changed

+1373
-1262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+1373
-1262
lines changed

src/Directory.Build.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
<RepositoryUrl>https://github.com/GitTools/GitVersion</RepositoryUrl>
1717
<RepositoryType>git</RepositoryType>
1818

19-
<NoWarn>1591</NoWarn>
19+
<NoWarn>1591,8618</NoWarn>
2020
<DebugType>embedded</DebugType>
2121
<LangVersion>10</LangVersion>
2222
<ImplicitUsings>enable</ImplicitUsings>
23+
<Nullable>enable</Nullable>
24+
2325
</PropertyGroup>
2426
<PropertyGroup>
2527
<PackageVersion_LibGit2Sharp>0.27.0-preview-0175</PackageVersion_LibGit2Sharp>

src/GitTools.Testing/Fixtures/RepositoryFixtureBase.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace GitTools.Testing;
88
/// </summary>
99
public abstract class RepositoryFixtureBase : IDisposable
1010
{
11-
private readonly SequenceDiagram sequenceDiagram;
1211

1312
protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder)
1413
: this(repoBuilder(PathHelper.GetTempPath()))
@@ -17,7 +16,7 @@ protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder)
1716

1817
protected RepositoryFixtureBase(IRepository repository)
1918
{
20-
this.sequenceDiagram = new SequenceDiagram();
19+
this.SequenceDiagram = new SequenceDiagram();
2120
Repository = repository;
2221
Repository.Config.Set("user.name", "Test");
2322
Repository.Config.Set("user.email", "[email protected]");
@@ -27,7 +26,8 @@ protected RepositoryFixtureBase(IRepository repository)
2726

2827
public string RepositoryPath => Repository.Info.WorkingDirectory.TrimEnd('\\');
2928

30-
public SequenceDiagram SequenceDiagram => this.sequenceDiagram;
29+
public SequenceDiagram SequenceDiagram { get; }
30+
3131

3232
/// <summary>
3333
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
@@ -57,10 +57,10 @@ protected virtual void Dispose(bool disposing)
5757
e.Message);
5858
}
5959

60-
this.sequenceDiagram.End();
60+
this.SequenceDiagram.End();
6161
Console.WriteLine("**Visualisation of test:**");
6262
Console.WriteLine(string.Empty);
63-
Console.WriteLine(this.sequenceDiagram.GetDiagram());
63+
Console.WriteLine(this.SequenceDiagram.GetDiagram());
6464
}
6565

6666
public void Checkout(string branch) => Commands.Checkout(Repository, branch);
@@ -75,28 +75,28 @@ public void MakeATaggedCommit(string tag)
7575

7676
public void ApplyTag(string tag)
7777
{
78-
this.sequenceDiagram.ApplyTag(tag, Repository.Head.FriendlyName);
78+
this.SequenceDiagram.ApplyTag(tag, Repository.Head.FriendlyName);
7979
Repository.ApplyTag(tag);
8080
}
8181

82-
public void BranchTo(string branchName, string @as = null)
82+
public void BranchTo(string branchName, string? @as = null)
8383
{
84-
this.sequenceDiagram.BranchTo(branchName, Repository.Head.FriendlyName, @as);
84+
this.SequenceDiagram.BranchTo(branchName, Repository.Head.FriendlyName, @as);
8585
var branch = Repository.CreateBranch(branchName);
8686
Commands.Checkout(Repository, branch);
8787
}
8888

89-
public void BranchToFromTag(string branchName, string fromTag, string onBranch, string @as = null)
89+
public void BranchToFromTag(string branchName, string fromTag, string onBranch, string? @as = null)
9090
{
91-
this.sequenceDiagram.BranchToFromTag(branchName, fromTag, onBranch, @as);
91+
this.SequenceDiagram.BranchToFromTag(branchName, fromTag, onBranch, @as);
9292
var branch = Repository.CreateBranch(branchName);
9393
Commands.Checkout(Repository, branch);
9494
}
9595

9696
public void MakeACommit()
9797
{
9898
var to = Repository.Head.FriendlyName;
99-
this.sequenceDiagram.MakeACommit(to);
99+
this.SequenceDiagram.MakeACommit(to);
100100
Repository.MakeACommit();
101101
}
102102

@@ -105,7 +105,7 @@ public void MakeACommit()
105105
/// </summary>
106106
public void MergeNoFF(string mergeSource)
107107
{
108-
this.sequenceDiagram.Merge(mergeSource, Repository.Head.FriendlyName);
108+
this.SequenceDiagram.Merge(mergeSource, Repository.Head.FriendlyName);
109109
Repository.MergeNoFF(mergeSource, Generate.SignatureNow());
110110
}
111111

src/GitTools.Testing/Fixtures/SequenceDiagram.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public SequenceDiagram()
3232
/// <summary>
3333
/// Creates a participant in the sequence diagram
3434
/// </summary>
35-
public void Participant(string participant, string @as = null)
35+
public void Participant(string participant, string? @as = null)
3636
{
3737
this.participants.Add(participant, @as ?? participant);
3838
if (@as == null)
@@ -49,7 +49,7 @@ public void Participant(string participant, string @as = null)
4949
/// <summary>
5050
/// Appends a note over one or many participants to the sequence diagram
5151
/// </summary>
52-
public void NoteOver(string noteText, string startParticipant, string endParticipant = null, string prefix = null, string color = null) =>
52+
public void NoteOver(string noteText, string startParticipant, string? endParticipant = null, string? prefix = null, string? color = null) =>
5353
this.diagramBuilder.AppendLineFormat(
5454
prefix + @"note over {0}{1}{2}
5555
{3}
@@ -67,7 +67,7 @@ public void NoteOver(string noteText, string startParticipant, string endPartici
6767
/// <summary>
6868
/// Appends branching from a branch to another branch, @as can override the participant name
6969
/// </summary>
70-
public void BranchTo(string branchName, string currentName, string @as)
70+
public void BranchTo(string branchName, string currentName, string? @as)
7171
{
7272
if (!this.participants.ContainsKey(branchName))
7373
{
@@ -84,7 +84,7 @@ public void BranchTo(string branchName, string currentName, string @as)
8484
/// <summary>
8585
/// Appends branching from a tag to a specified branch to the sequence diagram
8686
/// </summary>
87-
public void BranchToFromTag(string branchName, string fromTag, string onBranch, string @as)
87+
public void BranchToFromTag(string branchName, string fromTag, string onBranch, string? @as)
8888
{
8989
if (!this.participants.ContainsKey(branchName))
9090
{

src/GitTools.Testing/Generate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public static Signature SignatureNow()
1919
/// <summary>
2020
/// Creates a libgit2sharp signature at the specified time
2121
/// </summary>
22-
public static Signature Signature(DateTimeOffset dateTimeOffset) => new("A. U. Thor", "[email protected]", dateTimeOffset);
22+
private static Signature Signature(DateTimeOffset dateTimeOffset) => new("A. U. Thor", "[email protected]", dateTimeOffset);
2323
}

src/GitTools.Testing/GitTestExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class GitTestExtensions
77
{
88
private static int _pad = 1;
99

10-
public static Commit MakeACommit(this IRepository repository, string commitMessage = null) => CreateFileAndCommit(repository, Guid.NewGuid().ToString(), commitMessage);
10+
public static Commit MakeACommit(this IRepository repository, string? commitMessage = null) => CreateFileAndCommit(repository, Guid.NewGuid().ToString(), commitMessage);
1111

1212
public static void MergeNoFF(this IRepository repository, string branch) => MergeNoFF(repository, branch, Generate.SignatureNow());
1313

@@ -20,7 +20,7 @@ public static Commit[] MakeCommits(this IRepository repository, int numCommitsTo
2020
.Select(_ => repository.MakeACommit())
2121
.ToArray();
2222

23-
private static Commit CreateFileAndCommit(this IRepository repository, string relativeFileName, string commitMessage = null)
23+
private static Commit CreateFileAndCommit(this IRepository repository, string relativeFileName, string? commitMessage = null)
2424
{
2525
var randomFile = Path.Combine(repository.Info.WorkingDirectory, relativeFileName);
2626
if (File.Exists(randomFile))
@@ -68,7 +68,7 @@ public static Commit CreatePullRequestRef(this IRepository repository, string fr
6868
return commit;
6969
}
7070

71-
public static void ExecuteGitCmd(string gitCmd, Action<string> writer = null)
71+
public static void ExecuteGitCmd(string gitCmd, Action<string>? writer = null)
7272
{
7373
var output = new StringBuilder();
7474
try
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace GitTools.Testing.Internal;
2+
3+
public static class ObjectExtensions
4+
{
5+
public static void Deconstruct<TKey, TValue>(
6+
this KeyValuePair<TKey, TValue> kvp,
7+
out TKey key,
8+
out TValue value)
9+
{
10+
key = kvp.Key;
11+
value = kvp.Value;
12+
}
13+
}

src/GitTools.Testing/Internal/ProcessHelper.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public static class ProcessHelper
88
private static readonly object LockObject = new();
99

1010
// http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/f6069441-4ab1-4299-ad6a-b8bb9ed36be3
11-
private static Process Start(ProcessStartInfo startInfo)
11+
private static Process? Start(ProcessStartInfo startInfo)
1212
{
13-
Process process;
13+
Process? process;
1414

1515
lock (LockObject)
1616
{
@@ -74,15 +74,13 @@ private static Process Start(ProcessStartInfo startInfo)
7474
}
7575

7676
// http://csharptest.net/532/using-processstart-to-capture-console-output/
77-
public static int Run(Action<string> output, Action<string> errorOutput, TextReader input, string exe, string args, string workingDirectory, params KeyValuePair<string, string>[] environmentalVariables)
77+
public static int Run(Action<string> output, Action<string> errorOutput, TextReader? input, string exe, string args, string workingDirectory, params KeyValuePair<string, string>[] environmentalVariables)
7878
{
7979
if (string.IsNullOrEmpty(exe))
8080
throw new ArgumentNullException(nameof(exe));
8181
if (output == null)
8282
throw new ArgumentNullException(nameof(output));
8383

84-
workingDirectory ??= Environment.CurrentDirectory;
85-
8684
var psi = new ProcessStartInfo
8785
{
8886
UseShellExecute = false,
@@ -96,23 +94,31 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
9694
FileName = exe,
9795
Arguments = args
9896
};
99-
foreach (var environmentalVariable in environmentalVariables)
97+
foreach (var (key, value) in environmentalVariables)
10098
{
101-
if (psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key))
99+
var psiEnvironmentVariables = psi.EnvironmentVariables;
100+
if (psiEnvironmentVariables.ContainsKey(key) && string.IsNullOrEmpty(value))
102101
{
103-
psi.EnvironmentVariables[environmentalVariable.Key] = environmentalVariable.Value;
102+
psiEnvironmentVariables.Remove(key);
104103
}
105-
else
104+
else if (psiEnvironmentVariables.ContainsKey(key))
106105
{
107-
psi.EnvironmentVariables.Add(environmentalVariable.Key, environmentalVariable.Value);
106+
psiEnvironmentVariables[key] = value;
108107
}
109-
if (psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key) && environmentalVariable.Value == null)
108+
else
110109
{
111-
psi.EnvironmentVariables.Remove(environmentalVariable.Key);
110+
psiEnvironmentVariables.Add(key, value);
112111
}
113112
}
114113

115114
using var process = Start(psi);
115+
116+
if (process is null)
117+
{
118+
// FIX ME: What error code do you want to return?
119+
return -1;
120+
}
121+
116122
using var mreOut = new ManualResetEvent(false);
117123
using var mreErr = new ManualResetEvent(false);
118124
process.EnableRaisingEvents = true;
@@ -135,8 +141,8 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
135141
};
136142
process.BeginErrorReadLine();
137143

138-
string line;
139-
while (input != null && null != (line = input.ReadLine()))
144+
string? line;
145+
while ((line = input?.ReadLine()) != null)
140146
process.StandardInput.WriteLine(line);
141147

142148
process.StandardInput.Close();
@@ -160,7 +166,7 @@ private enum NativeErrorCode
160166
}
161167

162168
[Flags]
163-
public enum ErrorModes
169+
private enum ErrorModes
164170
{
165171
Default = 0x0,
166172
FailCriticalErrors = 0x1,
@@ -169,7 +175,7 @@ public enum ErrorModes
169175
NoOpenFileErrorBox = 0x8000
170176
}
171177

172-
private struct ChangeErrorMode : IDisposable
178+
private readonly struct ChangeErrorMode : IDisposable
173179
{
174180
private readonly int oldMode;
175181

src/GitTools.Testing/Internal/StringBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace GitTools.Testing.Internal;
55
internal static class StringBuilderExtensions
66
{
77
[StringFormatMethod("format")]
8-
public static void AppendLineFormat(this StringBuilder stringBuilder, string format, params object[] args)
8+
public static void AppendLineFormat(this StringBuilder stringBuilder, string format, params object?[] args)
99
{
1010
stringBuilder.AppendFormat(format, args);
1111
stringBuilder.AppendLine();

0 commit comments

Comments
 (0)