Skip to content

[Bug] NullReferenceException in test CacheKeySameAfterReNormalizing #2763

@Evangelink

Description

@Evangelink

Describe the bug

In GitPreparer there is a call to .Sha on the .Tip property without any null check. The interface doesn't declare nullability but the actual implementation does:

var expectedSha = repository.Head.Tip.Sha;

On main, I have the CacheKeySameAfterReNormalizing unit test failing with the following exception:

 CacheKeySameAfterReNormalizing
   Source: GitVersionExecutorTests.cs line 30
   Duration: 184 ms

  Message: 
    System.NullReferenceException : Object reference not set to an instance of an object.

  Stack Trace: 
    GitPreparer.NormalizeGitDirectory(Boolean noFetch, String currentBranchName, Boolean isDynamicRepository) line 169
    GitPreparer.NormalizeGitDirectory(String targetBranch, Boolean isDynamicRepository) line 147
    GitPreparer.CreateDynamicRepository(String targetBranch) line 138
    GitPreparer.PrepareInternal(Boolean normalizeGitDirectory, String currentBranch, Boolean shouldCleanUpRemotes) line 67
    GitPreparer.Prepare() line 59
    GitVersionExecutorTests.CacheKeySameAfterReNormalizing() line 50

  Standard Output: 
    Initialized empty Git repository in C:/Users/XXX/AppData/Local/Temp/TestRepositories/256f53f1-df99-46f4-b813-e466d9193819/.git/
    Created git repository at 'C:\Users\XXX\AppData\Local\Temp\TestRepositories\256f53f1-df99-46f4-b813-e466d9193819'
    **Visualisation of test:**
    
    @startuml
    @enduml

Expected Behavior

Test is green.

Actual Behavior

Test is failing.

Possible Fix

A null check should be added but I don't know what's the functional behavior to adopt when the sha is null.

Steps to Reproduce

Clone the project, go to the last commit, rebuild and run the test CacheKeySameAfterReNormalizing.

Your Environment

  • Version Used: a4e734a
  • Operating System and version (Windows 10, Ubuntu 18.04): Win 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions