[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Migrating from Jgit 1.0 to 1.1

Hi,

I could not make it work. Just to simplify things, I all want to do with Jgit 1.1 is this:

$ git brach newbranch -t origin/foo

Create a local branch tracking to a remote branch.

Thanks in advance,

Eduardo Falcão





2011/9/27 Matthias Sohn <matthias.sohn@xxxxxxxxxxxxxx>
2011/9/27 Eduardo Falcão <edu.falcao@xxxxxxxxx>
Hi,

I'm working in a project with Jgit 1.0 and I want to migrate to 1.1, but I'm stuck in one problem. Let me explain the workflow:

1) Let's assume that in my remote there are 3 branches: master, b1 and b2.
2) Clone remote repository with clonecommand passing the branch "master". This way my local repository is created and the local branch "master" is linked to the remote master.
        cc.setURI(remoteSSHConnection);
        cc.setDirectory(new File(localRepoPath));
        cc.setBranch("refs/heads/master");
        cc.setCredentialsProvider(credential);
        cc.call();

With JGit 1.0, I could run clonecommand again  in the same local repository passing "refs/heads/b1", and a local branch is created linked to remote. But in 1.1 an error occurs, saying that I cannot clone into a folder that already exists and is not empty. What do I have to do? All I want is to checkout in a branch that not exists locally, but it has to track the remote branch and have the same name. 
 
you can't clone into an existing repo, if that worked in 1.0 this was a bug

instead try the following:
- fetch the branch e.g. "foo" you want to have locally using refspec 
  refs/heads/foo:refs/remotes/origin/foo
  this creates the remote tracking branch refs/remotes/origin/foo
- create a local branch starting from this remote tracking branch and set the
  upstream configuration, you can do that using CheckoutCommand
  using setUpstreamMode()
- if you want to fetch updates and update this local branch run pull,
  the upstream configuration has established a tracking relationship
  so pull knows where to merge the new changes it has fetched for
  foo from the remote repository

use the corresponding commands from org.eclipse.jgit.api and
see the corresponding tests in bundle org.eclipse.jgit.test for
examples.
 
ps: With original git command line, if i checkout in a branch that not exist locally but exists in remote, it is automatically created locally and linked to remote

which command do you use for that ?
 
--
Matthias



--
Atenciosamente,

Eduardo Falcão