Skip to content

Fix all build warnings (unreachable code, nullable refs, and MSTEST)#81

Merged
Matt-17 merged 3 commits intomasterfrom
copilot/fix-8871cd75-141c-4934-9e95-4b2c1cdc2494
Sep 30, 2025
Merged

Fix all build warnings (unreachable code, nullable refs, and MSTEST)#81
Matt-17 merged 3 commits intomasterfrom
copilot/fix-8871cd75-141c-4934-9e95-4b2c1cdc2494

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 30, 2025

Summary

Fixes all 26 build warnings by addressing unreachable code, nullable reference issues, and obsolete MSTest attributes.

Problem

The build was generating 26 warnings:

  • 1 CS0162 warning due to unreachable code in GitVersionStartupService
  • 7 CS8602/CS8625 warnings for nullable reference dereferences
  • 12 MSTEST0039 warnings for using obsolete Assert.ThrowsException
  • 6 MSTEST0044 warnings for using obsolete DataTestMethod attribute

Solution

1. Unreachable Code (CS0162)

Following the issue requirement that "unreachable code should be commented and not deleted, as it might have a meaning":

  • Commented out the unreachable code block (lines 31-40) instead of removing it
  • Added explanatory comments documenting why the code is preserved:
    • The code searches for git installations in a "Gits" folder
    • It selects the best version from multiple git installations
    • It may be needed when supporting multiple git versions or custom git installations

2. Nullable Reference Warnings (CS8602/CS8625)

  • Added null-conditional operators (?.) for operations that could return null
  • Used null-forgiving operator (!) where values are guaranteed to be non-null in test contexts
  • Added proper null checks in benchmark code

3. MSTest Warnings (MSTEST0039 & MSTEST0044)

  • Replaced Assert.ThrowsException with Assert.ThrowsExactly for more precise exception type checking
  • Replaced Assert.ThrowsExceptionAsync with Assert.ThrowsExactlyAsync
  • Replaced obsolete [DataTestMethod] attribute with [TestMethod] (DataRow attributes continue to work correctly)

Changes

  • Modified: Gibbon.Git.Server/Git/GitVersionService/GitVersionStartupService.cs
  • Modified: Gibbon.Git.Server.Benchmarks/Program.cs
  • Modified: 15 test files to fix nullable reference and MSTest warnings

Testing

  • ✅ Build now completes with 0 warnings (down from 26)
  • ✅ All 254 tests pass (237 unit tests + 17 integration tests)
  • ✅ No functional changes - the behavior remains identical

Impact

This is a minimal, non-breaking change that eliminates all build warnings while preserving potentially useful code for future enhancements and improving test code quality.

Fixes #80

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix warning on build</issue_title>
<issue_description>As title describes, fix warnings on build.
Unreachable code should be commented and not deleted, as it might have a meaning. </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #80

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Matt-17 <11333169+Matt-17@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix warning on build Fix CS0162 unreachable code warning in GitVersionStartupService Sep 30, 2025
Copilot AI requested a review from Matt-17 September 30, 2025 14:19
@Matt-17
Copy link
Copy Markdown
Contributor

Matt-17 commented Sep 30, 2025

@copilot You missed all the other warnings ;-)

Co-authored-by: Matt-17 <11333169+Matt-17@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 30, 2025

@copilot You missed all the other warnings ;-)

Fixed all 25 remaining warnings in commit a33b208:

  • 7 nullable reference warnings (CS8602/CS8625)
  • 12 MSTEST0039 warnings (ThrowsException → ThrowsExactly)
  • 6 MSTEST0044 warnings (DataTestMethod → TestMethod)

Build now completes with 0 warnings, all 254 tests passing.

Copilot AI changed the title Fix CS0162 unreachable code warning in GitVersionStartupService Fix all build warnings (unreachable code, nullable refs, and MSTEST) Sep 30, 2025
@Matt-17 Matt-17 marked this pull request as ready for review September 30, 2025 15:06
@Matt-17 Matt-17 merged commit 05ea8e2 into master Sep 30, 2025
2 checks passed
@Matt-17 Matt-17 deleted the copilot/fix-8871cd75-141c-4934-9e95-4b2c1cdc2494 branch September 30, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix warning on build

2 participants