Skip to content

Commit

Permalink
Clean up more analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Mar 16, 2024
1 parent c407371 commit 729ef8d
Show file tree
Hide file tree
Showing 82 changed files with 223 additions and 225 deletions.
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToABlob()
{
AssertEnumerationOfCommits(
repo => new CommitFilter { IncludeReachableFrom = repo.Tags["point_to_blob"] },
new string[] { });
Array.Empty<string>());
}

[Fact]
Expand All @@ -421,7 +421,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToATree()

AssertEnumerationOfCommitsInRepo(repo,
r => new CommitFilter { IncludeReachableFrom = tag },
new string[] { });
Array.Empty<string>());
}
}

Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LibGit2Sharp.Tests
{
public class DiffTreeToTreeFixture : BaseFixture
{
private static readonly string subBranchFilePath = String.Join("/", "1", "branch_file.txt");
private static readonly string subBranchFilePath = string.Join("/", "1", "branch_file.txt");

[Fact]
public void ComparingATreeAgainstItselfReturnsNoDifference()
Expand All @@ -27,7 +27,7 @@ public void ComparingATreeAgainstItselfReturnsNoDifference()
using (var patch = repo.Diff.Compare<Patch>(tree, tree))
{
Assert.Empty(patch);
Assert.Equal(String.Empty, patch);
Assert.Equal(string.Empty, patch);
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions LibGit2Sharp.Tests/FetchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void CanFetchIntoAnEmptyRepository(string url)
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand All @@ -62,7 +62,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions
{
CredentialsProvider = Constants.PrivateRepoCredentials
}, null);
Expand Down Expand Up @@ -98,7 +98,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions
{
TagFetchMode = TagFetchMode.All,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
Expand Down Expand Up @@ -179,7 +179,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
r => r.TagFetchMode = tagFetchMode);

// Perform the actual fetch.
Commands.Fetch(repo, remoteName, new string[0], null, null);
Commands.Fetch(repo, remoteName, Array.Empty<string>(), null, null);

// Verify the number of fetched tags.
Assert.Equal(expectedTagCount, repo.Tags.Count());
Expand All @@ -197,7 +197,7 @@ public void CanFetchAllTagsAfterAnInitialClone()

using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
Commands.Fetch(repo, "origin", Array.Empty<string>(), new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
}
}

Expand All @@ -223,17 +223,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()

// No pruning when the configuration entry isn't defined
Assert.Null(clonedRepo.Config.Get<bool>("fetch.prune"));
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));

// No pruning when the configuration entry is set to false
clonedRepo.Config.Set<bool>("fetch.prune", false);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));

// Auto pruning when the configuration entry is set to true
clonedRepo.Config.Set<bool>("fetch.prune", true);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
}
}
Expand All @@ -248,10 +248,10 @@ public void CannotFetchWithForbiddenCustomHeaders()
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

const string knownHeader = "User-Agent: mygit-201";
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null));
}
}

Expand All @@ -265,10 +265,10 @@ public void CanFetchWithCustomHeaders()
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

const string knownHeader = "X-Hello: mygit-201";
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], options, null);
Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null);
}
}

Expand All @@ -282,10 +282,10 @@ public void CannotFetchWithMalformedCustomHeaders()
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

const string knownHeader = "Hello world";
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null));
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/FilterBranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void CanRewriteTreesByInjectingTreeEntry()

AssertSucceedingButNotError();

Assert.Equal(new Commit[0],
Assert.Equal(Array.Empty<Commit>(),
repo.Commits
.QueryBy(new CommitFilter {IncludeReachableFrom = repo.Branches})
.Where(c => c["README"] != null
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/FilterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin
return expectedPath;
}

private static FileInfo CommitFileOnBranch(Repository repo, string branchName, String content)
private static FileInfo CommitFileOnBranch(Repository repo, string branchName, string content)
{
var branch = repo.CreateBranch(branchName);
Commands.Checkout(repo, branch.FriendlyName);
Expand Down
14 changes: 7 additions & 7 deletions LibGit2Sharp.Tests/MetaFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
var typesWithDebuggerDisplayAndInvalidImplPattern = new List<Type>();

IEnumerable<Type> libGit2SharpTypes = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
.Where(t => t.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Any());
.Where(t => t.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Length != 0);

foreach (Type type in libGit2SharpTypes)
{
Expand All @@ -110,7 +110,7 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
}
}

if (typesWithDebuggerDisplayAndInvalidImplPattern.Any())
if (typesWithDebuggerDisplayAndInvalidImplPattern.Count != 0)
{
Assert.Fail(Environment.NewLine + BuildMissingDebuggerDisplayPropertyMessage(typesWithDebuggerDisplayAndInvalidImplPattern));
}
Expand All @@ -131,7 +131,7 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
continue;

var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList();
if (nonVirtualMethodNamesForType.Any())
if (nonVirtualMethodNamesForType.Count != 0)
{
nonTestableTypes.Add(type, nonVirtualMethodNamesForType);
continue;
Expand Down Expand Up @@ -165,7 +165,7 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
}
}

if (nonTestableTypes.Any())
if (nonTestableTypes.Count != 0)
{
Assert.Fail(Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
}
Expand Down Expand Up @@ -193,7 +193,7 @@ private static bool MustBeMockable(Type type)
public void EnumsWithFlagsHaveMutuallyExclusiveValues()
{
var flagsEnums = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
.Where(t => t.GetTypeInfo().IsEnum && t.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any());
.Where(t => t.GetTypeInfo().IsEnum && t.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Length != 0);

var overlaps = from t in flagsEnums
from int x in Enum.GetValues(t)
Expand Down Expand Up @@ -277,7 +277,7 @@ public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability()
(!m.IsVirtual || m.IsFinal))
.ToList();

if (nonVirtualGetEnumeratorMethods.Any())
if (nonVirtualGetEnumeratorMethods.Count != 0)
{
var sb = new StringBuilder();

Expand Down Expand Up @@ -306,7 +306,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
.Where(t => t.FullName != "LibGit2Sharp.Core.LeaksContainer")
.ToList();

if (types.Any())
if (types.Count != 0)
{
var sb = new StringBuilder();

Expand Down
8 changes: 4 additions & 4 deletions LibGit2Sharp.Tests/NetworkFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void CanMergeFetchedRefs()
Assert.False(repo.RetrieveStatus().Any());
Assert.Equal(repo.Lookup<Commit>("refs/remotes/origin/master~1"), repo.Head.Tip);

Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null);
Commands.Fetch(repo, repo.Head.RemoteName, Array.Empty<string>(), null, null);

MergeOptions mergeOptions = new MergeOptions()
{
Expand All @@ -276,7 +276,7 @@ public void CanPruneRefs()
using (var repo = new Repository(clonedRepoPath))
{
repo.Network.Remotes.Add("pruner", clonedRepoPath2);
Commands.Fetch(repo, "pruner", new string[0], null, null);
Commands.Fetch(repo, "pruner", Array.Empty<string>(), null, null);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);

// Remove the branch from the source repository
Expand All @@ -286,11 +286,11 @@ public void CanPruneRefs()
}

// and by default we don't prune it
Commands.Fetch(repo, "pruner", new string[0], null, null);
Commands.Fetch(repo, "pruner", Array.Empty<string>(), null, null);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);

// but we do when asked by the user
Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true }, null);
Commands.Fetch(repo, "pruner", Array.Empty<string>(), new FetchOptions { Prune = true }, null);
Assert.Null(repo.Refs["refs/remotes/pruner/master"]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/ReferenceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ public void CanHandleInvalidArguments()
Assert.Throws<ArgumentNullException>(() => repo.Refs.ReachableFrom(null));
Assert.Throws<ArgumentNullException>(() => repo.Refs.ReachableFrom(null, repo.Commits.Take(2)));
Assert.Throws<ArgumentNullException>(() => repo.Refs.ReachableFrom(repo.Refs, null));
Assert.Empty(repo.Refs.ReachableFrom(new Commit[] { }));
Assert.Empty(repo.Refs.ReachableFrom(Array.Empty<Commit>()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/RemoveFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void RemovingFileWithBadParamsThrows()
{
Assert.Throws<ArgumentException>(() => Commands.Remove(repo, string.Empty));
Assert.Throws<ArgumentNullException>(() => Commands.Remove(repo, (string)null));
Assert.Throws<ArgumentException>(() => Commands.Remove(repo, new string[] { }));
Assert.Throws<ArgumentException>(() => Commands.Remove(repo, Array.Empty<string>()));
Assert.Throws<ArgumentNullException>(() => Commands.Remove(repo, new string[] { null }));
}
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ public void CanFetchFromRemoteByName()
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);

// Verify the expected state
expectedFetchState.CheckUpdatedReferences(repo);

// Now fetch the rest of the tags
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions { TagFetchMode = TagFetchMode.All }, null);

// Verify that the "nearly-dangling" tag is now in the repo.
Tag nearlyDanglingTag = repo.Tags["nearly-dangling"];
Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp.Tests/StageFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void StagingFileWithBadParamsThrows()
{
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, string.Empty));
Assert.Throws<ArgumentNullException>(() => Commands.Stage(repo, (string)null));
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, new string[] { }));
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, Array.Empty<string>()));
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, new string[] { null }));
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ public void IgnoredFilesAreOnlyStagedIfTheyreInTheRepo(string filename, FileStat
using (var repo = new Repository(path))
{
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, ".gitignore"),
String.Format("{0}\n", filename));
string.Format("{0}\n", filename));

Commands.Stage(repo, filename);
Assert.Equal(expected, repo.RetrieveStatus(filename));
Expand All @@ -384,7 +384,7 @@ public void CanStageConflictedIgnoredFiles(string filename, FileStatus expected)
using (var repo = new Repository(path))
{
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, ".gitignore"),
String.Format("{0}\n", filename));
string.Format("{0}\n", filename));

Commands.Stage(repo, filename);
Assert.Equal(expected, repo.RetrieveStatus(filename));
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/TestHelpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public static string BuildPath()
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
{
Trace.TraceInformation("{0} environment variable detected", LibGit2TestPath);
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as String;
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as string;
}

if (String.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
if (string.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
{
Trace.TraceInformation("Using default test path value");
tempPath = Path.GetTempPath();
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/UnstageFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void UnstagingFileWithBadParamsThrows()
{
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, string.Empty));
Assert.Throws<ArgumentNullException>(() => Commands.Unstage(repo, (string)null));
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, new string[] { }));
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, Array.Empty<string>()));
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, new string[] { null }));
}
}
Expand Down
Loading

0 comments on commit 729ef8d

Please sign in to comment.