<< Back to previous view |
![]() |
[QB-2759] Enhance Git support to checkout branch
|
|
Status: | Closed |
Project: | QuickBuild |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Improvement | Priority: | Major |
Reporter: | Justin Georgeson | Assigned To: | Robin Shen |
Resolution: | Won't Fix | Votes: | 0 |
Remaining Estimate: | Unknown | Time Spent: | Unknown |
Original Estimate: | Unknown |
Description |
Currently for Git repositories, QuickBuild always checks out a detached head. I understand the purpose, to ensure the checked out state matches the pre-build snapshot. However not having a branch checked out is problematic for build tool plugins that find and record SCM information. It's pretty simple to check the requested branch's revision against the checkout revision and checkout the branch if same. Here is sample post-execute Groovy script that I tested on a checkout step
groovy: import com.pmease.quickbuild.plugin.scm.git.GitCli; def git = new GitCli(step.repository) def shortBranch = step.repository.getActualBranch() String branchRev = git.revision(shortBranch) String revision = step.repository.getRevision() logger.info("Requested branch '" + shortBranch + "' has revision '" + branchRev + "'") logger.info("Build revision is " + revision) if (branchRev.equals(revision)) { logger.info("Checking out branch") git.checkout(shortBranch) } Alternatively (and probably simpler) would be to 'checkout -f' the requested branch to the revision in the snapshot. |
Comments |
Comment by Robin Shen [ 15/Jul/16 11:46 PM ] |
To do that, you may add a command build step after the checkout step doing below:
git checkout <your branch> |
Comment by Justin Georgeson [ 18/Jul/16 03:03 PM ] |
I can, but it would be nicer to have it done automatically, even if there's a checkbox I have to click to enable it. |
Comment by Robin Shen [ 19/Jul/16 12:46 AM ] |
I do not think it is a good idea to put that one into checkout workflow directly as the most important thing is to make sure the source used across the build remains consistent. |
Comment by Justin Georgeson [ 19/Jul/16 01:28 PM ] |
I agree that it should be consistent. That's why I shared code that confirms consistency before checking out the branch. And assuming you are setting the checkout revision during snapshot by looking at the remote branch pointer before the build starts, the simpler method of running 'checkout -f' internally is safe and consistent because that's where the branch pointer was as the time of snapshot and all nodes will set their branch pointer to that same revision. A 'checkout -f' is safe to combine with a subsequent tag step because you haven't diverged the branch between local/remote (you only push the tag, not the local branch pointer).
When you're already taking the resource hit to fetch the entire repo it's frustrating to not have the benefit of regular branch checkout without custom steps/code. I'd be more understanding if you were doing shallow clones that would require further network traffic and disk space to get from detached HEAD to branch. |
Comment by Robin Shen [ 19/Jul/16 11:23 PM ] |
Sorry we'd rather not to add that extra option to further complicate the already complicated git repository definition, as we only hear very few users having this requirement (changing SCM information during build). Also QB suggests not to modify the source code during build and putting code in detached head instead of branch serves our primary purpose. |
Comment by Robin Shen [ 01/Dec/16 07:31 AM ] |
Or a script to call below:
repositories.get("repo name").switchToHead(); |