dotnet / Nerdbank.GitVersioning

Stamp your assemblies, packages and more with a unique version generated from a single, simple version.json file and include git commit IDs for non-official builds.
https://www.nuget.org/packages/Nerdbank.GitVersioning
MIT License
1.32k stars 165 forks source link

Regression: cannot parse commitishes like HEAD~2 #572

Open heaths opened 3 years ago

heaths commented 3 years ago

nbgv version 3.3.37+0989e8fe0c could parse commitishes like HEAD~2 but the latest version build from master cannot. It yields an exception:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(ReadOnlySpan`1 str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(ReadOnlySpan`1 s, NumberStyles style, NumberFormatInfo info)
   at System.Byte.Parse(ReadOnlySpan`1 s, NumberStyles style, NumberFormatInfo info)
   at System.Byte.Parse(String s, NumberStyles style, IFormatProvider provider)
   at Nerdbank.GitVersioning.ManagedGit.GitRepository.ConvertHexStringToByteArray(String hexString) in C:\src\Nerdbank.GitVersioning\src\NerdBank.GitVersioning\ManagedGit\GitRepository.cs:line 724
   at Nerdbank.GitVersioning.ManagedGit.GitRepository.Lookup(String objectish) in C:\src\Nerdbank.GitVersioning\src\NerdBank.GitVersioning\ManagedGit\GitRepository.cs:line 405
   at Nerdbank.GitVersioning.Managed.ManagedGitContext.TrySelectCommit(String committish) in C:\src\Nerdbank.GitVersioning\src\NerdBank.GitVersioning\Managed\ManagedGitContext.cs:line 66
   at Nerdbank.GitVersioning.Tool.Program.OnGetVersionCommand(String projectPath, IReadOnlyList`1 buildMetadata, String format, String singleVariable, String versionOrRef) in C:\src\Nerdbank.GitVersioning\src\nbgv\Program.cs:line 330
   at Nerdbank.GitVersioning.Tool.Program.MainInner(String[] args) in C:\src\Nerdbank.GitVersioning\src\nbgv\Program.cs:line 165
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Nerdbank.GitVersioning.Tool.Program.Main(String[] args) in C:\src\Nerdbank.GitVersioning\src\nbgv\Program.cs:line 76
AArnott commented 3 years ago

This is an expected regression from #521 (CC: @qmfrederik). We only support (partial) commit IDs and refs at this point unless you explicitly. You should be able to workaround it by switching to the libgit2 engine as described in our release notes.

Supporting all the various committish forms in the all-managed engine would be a large undertaking I suspect. I am curious why you were doing this and how often you anticipate hitting this.

heaths commented 3 years ago

Was trying various scenarios using the latest nbgv global tool release and what I had in my branch for #567. For a while, I thought somehow my code changes broke this (something to do with the parsing), but after stashing and switching back to master, found it was broken before (same as with the other bug).

If it's not supported, I understand. But might want to catch the issue and gracefully error or throw a new exception with a more friendly error. The error message itself isn't obvious unless you look further down the stack, and not everyone using nbgv may find that so easy.

qmfrederik commented 3 years ago

Looking from the docs, there are two types of Ancestry References which are supported:

So you can have HEAD, HEAD^, HEAD^2, HEAD~ or HEAD~n. These can be combined, so you can have something like HEAD~3^2.