History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: QB-2759
Type: Improvement Improvement
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Robin Shen
Reporter: Justin Georgeson
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
QuickBuild

Enhance Git support to checkout branch

Created: 15/Jul/16 05:06 PM   Updated: 01/Dec/16 07:31 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown


 Description  « Hide
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.

 All   Comments   Work Log   Change History      Sort Order:
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>

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.

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.

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.

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.

Robin Shen [01/Dec/16 07:31 AM]
Or a script to call below:
repositories.get("repo name").switchToHead();