0

I'm cloning a remote repository and want to checkout several branches to interoperate with them (without applying changes to the working directory).

So I clone the repository:

CloneCommand clone = Git.cloneRepository();
clone.setURI(project.getUrl());
clone.setDirectory(new File(RepositoryHandlerHelper
        .getFilePath(project)));
clone.setCredentialsProvider(getCredentials());
clone.setCloneAllBranches(true);

clone.call();

And that works. Now I create the remote branches on my local harddrive (in a loop):

git.branchCreate().setName(currentBranchToBuild)
.setUpstreamMode(SetupUpstreamMode.TRACK)
.call();

Which works as well. I'm not sure this is necessary though.. After that I try to checkout each branch:

git.checkout().setName(currentBranchToBuild).call();

I'm sure right branch name is submitted to setName(). No Exception is thrown but the command does not seem to take any effect on my working directory.

Am I missing something here?

dwalldorf
  • 1,379
  • 3
  • 12
  • 21
  • 1
    The last two code blocks have exactly the same code, I'm guessing the latter one should be `git.checkout()`? – robinst Oct 26 '12 at 13:12

2 Answers2

1

I guess you need to add setStartPoint("origin/branchtotrack"), also see my answer to a similar question.

Community
  • 1
  • 1
robinst
  • 30,027
  • 10
  • 102
  • 108
  • I tried this: `git.checkout().setStartPoint("origin/" + currentBranchToBuild).setName(currentBranchToBuild).call();` But it didn't change anything. Is that what you meant? – dwalldorf Oct 26 '12 at 14:46
0

Found a working solution: I don't need to create a local copy of each branch. If I just do a checkout of the remote branch it works. My problem was something different. I'm generating JavaDoc of each branch (checkout then create JavaDoc). But it seems like the checkout does not take effect immediately. If I put a Thread.sleep(1000) between git.checkout... and my call to generate the JavaDoc, it works just fine.

Thanks for the help.

dwalldorf
  • 1,379
  • 3
  • 12
  • 21