Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Probleme with porcelaine.

On Mon, Sep 27, 2010 at 9:47 AM, Jérôme Blanchard <jayblanc@xxxxxxxxx> wrote:
> I have latest jgit version (0.10.SNAPSHOT) and I'm trying the following
> scenario :
> 1. create a central bare repository
> 2. clone it
> 3. create 2 test files
> 4. add them into the index
> 5. commit changes
> 6. push everything in the central repository
> 7. clone the  central repository
> 8. perform a fetch
> 9. compare the files...
> And when I try to perform step 8 I have an exception :
> java.lang.NullPointerException
>     at org.eclipse.jgit.revwalk.RevWalk.parseCommit(
>     at
> org.qualipso.factory.git.test.LocalGitTest.testCreateAddAndCommitToLocalRepository(
> After some inspections, it seem that there is no master to update but I
> can't figure it out.

Yes, that is exactly what your problem is.  There isn't a master
branch yet after step 8.  But your test is looking for it anyway.

>             repository2 = new
> FileRepositoryBuilder().setGitDir(repositoryFolder2).build();
>             git = new Git(repository2);
>             FetchResult fr = git.fetch().call();
>             for ( TrackingRefUpdate update : fr.getTrackingRefUpdates() ) {
>                 logger.debug(update.getResult().name());
>             }
>             logger.debug("result : " + fr.getMessages());

If you run `git for-each-ref`, or use repository2.getAllRefs() at this
point I think you will see that you only have refs under
refs/remotes/origin/ directory, e.g. refs/remotes/origin/master.
There is no HEAD ref, and there is no refs/heads/master.  The fetch
has copied the remote repository's objects local, and updated the
local tracking refs under the refs/remotes/ namespace, but it doesn't
touch your local branches.

>             Ref refHead = repository2.getRef(Constants.HEAD);
>             RevWalk walk = new RevWalk(repository2);
>             RevCommit revCommit = walk.parseCommit(refHead.getObjectId());

So here you have null coming back from refHead.getObjectId() because
HEAD is pointing to refs/heads/master, which doesn't yet exist
locally.  You'll need to first create that branch before doing the
above steps.  Do that with:

  RefUpdate u = repository2.updateRef(Constants.HEAD);

Or something similar to figure out what the remote gave you when you
did the fetch part.  You can actually look at the FetchResult object
to see what you were given and use that to help you figure out what
you should be setting HEAD to.  Actually, what the command line C Git
implementation tries to do is:



Back to the top