Skip to content

[Bug]Failed to try and guess branch to use. Move one of the branches along a commit to remove warning #2927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hyabean opened this issue Nov 30, 2021 · 5 comments · Fixed by #2933 or #2951
Labels
Milestone

Comments

@hyabean
Copy link
Contributor

hyabean commented Nov 30, 2021

Describe the bug
when build a tag commit on a jenkins agent, it failed and report
"[2021-11-29 16:47:39] WARN [11/29/21 16:47:39:51] An error occurred:
[2021-11-29 16:47:39] Failed to try and guess branch to use. Move one of the branches along a commit to remove warning"

Expected Behavior

build success

Actual Behavior

build failed

Possible Fix

if current commit tagged, not throw a excpetion.

throw new WarningException("Failed to try and guess branch to use. " + moveBranchMsg);

Steps to Reproduce

  1. add a Environment Variable in Windows "JENKINS_URL" in Windows, act as a jenkins agent
  2. open a powershell and execute:
mkdir gitversionErrorTest
cd gitversionErrorTest
git init
git.exe config remote.origin.url https://github.com/hyabean/GitVersionBuildFail.git # timeout=10
git.exe fetch --tags --force --progress -- https://github.com/hyabean/GitVersionBuildFail.git +refs/heads/*:refs/remotes/origin/* +refs/merge/*:refs/remotes/origin/merge/*
git.exe rev-parse "b309af2d6845182e643eb60ee06ebe9aecf8425e^{commit}" # timeout=10
git.exe config core.sparsecheckout # timeout=10
git.exe checkout -f b309af2d6845182e643eb60ee06ebe9aecf8425e
dotnet-gitversion ".\src\TcWinApp" -output file -outputfile src\TcWinApp\obj\gitversion.json

Context

CI failed after tag

Your Environment

企业微信截图_16382739727145

  • Version Used:
  • GitVersion Version 5.7.0
@hyabean hyabean added the bug label Nov 30, 2021
@asbjornu
Copy link
Member

GitVersion's requirements state:

The repository should be switched to a named, existing branch pointing to the commit being built (i.e. no detached HEAD).

@hyabean hyabean changed the title [Bug] [Bug]Failed to try and guess branch to use. Move one of the branches along a commit to remove warning Nov 30, 2021
@hyabean
Copy link
Contributor Author

hyabean commented Nov 30, 2021

GitVersion's requirements state:

The repository should be switched to a named, existing branch pointing to the commit being built (i.e. no detached HEAD).

I know the requirements. But it isn't always fail when in detached HEAD. In some detached condition, GitVersion will help switch to the right branch. It switches to main branch (if the main branch's HEAD equals the commit) or proper branch (if found only one branch which name without separator).
The problem occurs when
when 1. Build on Jenkins agent
and 2. Detached HEAD
and 3. Have more than one branch with the HEAD equals the building commit
and 4. Have no branch without separator('/', '-')

If I don't build on a Jenkins agent, git version will run success. So I think It is an accidental bug. It often interrupts our CI workflow.

In my situation, The commit is tagged, I think the semanticVersion is definite.
Switching to any proper branch or staying detached HEAD is acceptable.

@asbjornu
Copy link
Member

asbjornu commented Dec 1, 2021

I don't use Jenkins myself and have no use for building detached HEADs, but if you figure out a way to solve this (with tests), I'd be happy to merge a PR.

@hyabean
Copy link
Contributor Author

hyabean commented Dec 4, 2021

I don't use Jenkins myself and have no use for building detached HEADs, but if you figure out a way to solve this (with tests), I'd be happy to merge a PR.

@asbjornu Please review #2933.

@github-actions
Copy link

🎉 This issue has been resolved in version 5.8.2 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

hyabean added a commit to hyabean/GitVersion that referenced this issue Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment