GitVersion icon indicating copy to clipboard operation
GitVersion copied to clipboard

[Improvement] Better error message when in detached head

Open Evangelink opened this issue 4 years ago • 8 comments

Is your improvement request related to a problem? Please describe.

When re-building a commit in history, I often fail to remember to comment the GitVersion.MsBuild package reference from my project. Which results in one failure per project with the following message:

Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB3073	The command ""C:\Users\XXX\.nuget\packages\gitversion.msbuild\5.6.10\tools\net48/gitversion.exe" "C:\Src\YYY" -output file -outputfile obj\gitversion.json" exited with code 1.	YYY	C:\Users\XXX\.nuget\packages\gitversion.msbuild\5.6.10\tools\GitVersion.MsBuild.targets	9	

This error message is pretty generic and could (maybe?) be improved for the case of detached head with a more helpful message.

Detailed Description

Either return a different exit code and document it and/or fail with a message that would be displayed. I haven't done msbuild tasks for quite some time and so I don't really remember what's possible and how to do so.

Context

Relates to #2697

Possible Implementation

Evangelink avatar Jul 15 '21 13:07 Evangelink

Improvements in error messages are always welcome! A PR would be highly appreciated. 🙏🏼

asbjornu avatar Jul 15 '21 20:07 asbjornu

I will try to provide something but if you have some spare time for a couple of advices, they would be welcome :)

Evangelink avatar Jul 15 '21 21:07 Evangelink

If you are able to reproduce the problem with the command line, we can see whether the exception thrown is something sensible and start from there.

asbjornu avatar Jul 15 '21 23:07 asbjornu

Just for the sake of grouping the info together, here are the steps to reproduce the issue:

  • Install GitVersion on a project
  • Make some commit
  • Checkout previous commit
  • Rebuild solution
  • Build fail with error saying gitversion.exe failed

Evangelink avatar Jul 16 '21 16:07 Evangelink

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 02 '22 11:03 stale[bot]

A PR that improves the error message of detached heads is still very welcome. :)

asbjornu avatar Mar 02 '22 23:03 asbjornu

Hey @asbjornu! I am really sorry about all that delay. I had a pretty busy end of year, I will try to give it a go during the week-end.

Evangelink avatar Mar 03 '22 08:03 Evangelink

No problem, @Evangelink. Take we're in no rush. :)

asbjornu avatar Mar 03 '22 13:03 asbjornu

Fixed by #3338.

asbjornu avatar Jan 20 '23 10:01 asbjornu

:tada: This issue has been resolved in version 5.12.0 :tada: The release is available on:

Your GitReleaseManager bot :package::rocket:

arturcic avatar Jan 20 '23 14:01 arturcic

I just got the same error again with 5.12.0:

  ERROR [07/31/23 12:27:11:55] An unexpected error occurred:
[12:27:11]GitVersion.BugException: GitVersion has a bug, your HEAD has moved after repo normalisation.
[12:27:11]
[12:27:11]To disable this error set an environmental variable called IGNORE_NORMALISATION_GIT_HEAD_MOVE to 1
[12:27:11]
[12:27:11]Please run `git log --graph --format="%h %cr %d" --decorate --date=relative --all --remotes=* -n 100` and submit it along with your build log (with personal info removed) in a new issue at https://github.com/GitTools/GitVersion
[12:27:11]   at GitVersion.GitPreparer.NormalizeGitDirectory(Boolean noFetch, String currentBranchName, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 192
[12:27:11]   at GitVersion.GitPreparer.NormalizeGitDirectory(String targetBranch, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 134
[12:27:11]   at GitVersion.GitPreparer.PrepareInternal(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 69
[12:27:11]   at GitVersion.GitPreparer.Prepare() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 48
[12:27:11]   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 43
[12:27:11]   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
[12:27:11]Process exited with code 1

When IGNORE_NORMALISATION_GIT_HEAD_MOVE to 1 is added, as recommended here, GitVersion incorrectly picks latest commit and calculates wrong version number of the build.

nenadvicentic avatar Jul 31 '23 10:07 nenadvicentic