Skip to content

Getting the build version fails for repositories cloned with --no-tags #1150

@mkaring

Description

@mkaring

In case a repository is cloned with the --no-tags flag, Nerdbank.GitVersioning will fail in dotnet builds, due to the attempt to access a directory that does not exist.

Error Message

<snip>\out\nuget\nerdbank.gitversioning\3.7.112\build\Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
System.IO.DirectoryNotFoundException: Could not find a part of the path '<snip>\.git\refs\tags'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)
   at Nerdbank.GitVersioning.ManagedGit.GitRepository.LookupTags(GitObjectId objectId)
   at Nerdbank.GitVersioning.Managed.ManagedGitContext.get_HeadTags()
   at Nerdbank.GitVersioning.VersionOracle..ctor(GitContext context, ICloudBuild cloudBuild, Nullable`1 overrideVersionHeightOffset)
   at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() in D:\a\1\s\src\Nerdbank.GitVersioning.Tasks\GetBuildVersion.cs:line 247
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [<snip>\out\nuget\nerdbank.gitversioning\3.7.112\build\PrivateP2PCaching.proj]

This error was introduced by this pull request: #876

The first affected version is v3.7.112.
v3.6.146 works without issue.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions