Skip to main content

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

Hy all,

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...

Something quite simple ; but it seems there is some problems.

First of all when I do a gitk after step 5 I have some errors in the repository (see screenshot1)
And when I try to perform step 8 I have an exception :

java.lang.NullPointerException
    at org.eclipse.jgit.lib.ObjectIdSubclassMap.index(ObjectIdSubclassMap.java:172)
    at org.eclipse.jgit.lib.ObjectIdSubclassMap.get(ObjectIdSubclassMap.java:89)
    at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:809)
    at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:724)
    at org.qualipso.factory.git.test.LocalGitTest.testCreateAddAndCommitToLocalRepository(LocalGitTest.java:175)

After some inspections, it seem that there is no master to update but I can't figure it out.

Is somebody have some ideas ??

The source code of this test is here :

            //Create a central GIT repository :
            logger.debug("creating a central bare repository ");
            File centralFolder = new File(workingDir, "centralgit");
            Repository centralRepo = new FileRepositoryBuilder().setGitDir(centralFolder).build();
            centralRepo.create(true);
            URIish centralURI = new URIish("file://" + centralFolder.getCanonicalPath());
            centralRepo.close();
           
            // Clone the central repository in local :
            logger.debug("cloning the central repository in repository 1");
            File workFolder1 = new File(workingDir, "testgit1");
            File repositoryFolder1 = new File(workFolder1, ".git");
            Repository repository1 = new FileRepositoryBuilder().setGitDir(repositoryFolder1).build();
            repository1.create();
            RemoteConfig rc1 = new RemoteConfig(centralRepo.getConfig(), Constants.DEFAULT_REMOTE_NAME);
            rc1.addURI(centralURI);
            rc1.addFetchRefSpec(new RefSpec().setForceUpdate(true)
                    .setSourceDestination(Constants.R_HEADS + "*",
                            Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/*"));
            rc1.update(repository1.getConfig());
            repository1.getConfig().save();
            dumpRepository(repository1);
            repository1.close();
           
            // Create some file
            logger.debug("Adding some content in repositroy 1");
            File file11 = new File(workFolder1, "testfile1.txt");
            FileOutputStream fos11 = new FileOutputStream(file11);
            fos11.write("Yeapa\r\n".getBytes());
            fos11.flush();
            fos11.close();
            File file12 = new File(workFolder1, "testfile2.txt");
            FileOutputStream fos12 = new FileOutputStream(file12);
            fos12.write("Youpi !!!\r\n".getBytes());
            fos12.flush();
            fos12.close();
           
            //Commit in repositroy1
            repository1 = new FileRepositoryBuilder().setGitDir(repositoryFolder1).build();
            Git git = new Git(repository1);
            git.add().addFilepattern("testfile1.txt").addFilepattern("testfile2.txt").call();
            dumpRepository(repository1);
            repository1.close();
            repository1 = new FileRepositoryBuilder().setGitDir(repositoryFolder1).build();
            git = new Git(repository1);
            git.commit().setAuthor("jayblanc", "jayblanjc@xxxxxxxxx").setMessage("yeapa\r\n").setAll(true).call();
            dumpRepository(repository1);
            repository1.close();
           
            // Push the commit from repository 1 to central repository
            logger.debug("Pushing into central repository at uri : " + centralURI);
            repository1 = new FileRepositoryBuilder().setGitDir(repositoryFolder1).build();
            Transport transport = Transport.open(repository1, centralURI);
            transport.setPushThin(Transport.DEFAULT_PUSH_THIN);
            transport.setDryRun(false);
            Collection<RefSpec> refs = new Vector<RefSpec>();
            refs.add(Transport.REFSPEC_PUSH_ALL);
            Collection<RemoteRefUpdate> toPush = transport.findRemoteRefUpdatesFor(refs);
            PushResult result;
            try {
                result = transport.push(new TextProgressMonitor(), toPush);
            } finally {
                transport.close();
            }
            logger.debug("Push result Message : " + result.getMessages());
           
            // Clone the repository into new local one.
            logger.debug("Cloning central repository into repository2");
            File workFolder2 = new File(workingDir, "testgit2");
            File repositoryFolder2 = new File(workFolder2, ".git");
            Repository repository2 = new FileRepositoryBuilder().setGitDir(repositoryFolder2).build();
            repository2.create();
            RemoteConfig rc = new RemoteConfig(repository2.getConfig(), Constants.DEFAULT_REMOTE_NAME);
            rc.addURI(centralURI);
            rc.addFetchRefSpec(new RefSpec().setForceUpdate(true)
                    .setSourceDestination(Constants.R_HEADS + "*",
                            Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/*"));
            rc.update(repository2.getConfig());
            repository2.getConfig().save();
            repository2.close();

            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());
           
           
            Ref refHead = repository2.getRef(Constants.HEAD);
            RevWalk walk = new RevWalk(repository2);
            RevCommit revCommit = walk.parseCommit(refHead.getObjectId());
            RefUpdate u = repository2.updateRef(Constants.HEAD);
            u.setNewObjectId(revCommit);
            u.forceUpdate();

            DirCache dirCache = DirCache.lock(repository2.getIndexFile(), FS.DETECTED);
            DirCacheCheckout dcco = new DirCacheCheckout(repository2, refHead.getObjectId(), dirCache, revCommit.getTree().getId());
            dcco.checkout();
            dumpRepository(repository2);
            repository2.close();

Attachment: screenshot1.png
Description: PNG image


Back to the top