Package org.eclipse.jgit.api

Examples of org.eclipse.jgit.api.Git


        ClientSession session = client.connect("sshd", "localhost", 8001).await().getSession();
        session.addPasswordIdentity("sshd");
        session.auth().verify();

        Git.init().setDirectory(repo).call();
        Git git = Git.open(repo);
        git.commit().setMessage("First Commit").setCommitter("sshd", "sshd@apache.org").call();

        new File("target/git/pgm/test/readme.txt").createNewFile();
        execute(session, "git --git-dir test add readme.txt");

        execute(session, "git --git-dir test commit -m \"readme\"");
View Full Code Here


        Git.cloneRepository()
                .setURI("ssh://sshd@localhost:8001/test.git")
                .setDirectory(dir)
                .call();

        Git git = Git.open(dir);
        git.commit().setMessage("First Commit").setCommitter("sshd", "sshd@apache.org").call();
        git.push().call();

        new File("target/git/local/test.git/readme.txt").createNewFile();
        git.add().addFilepattern("readme.txt").call();
        git.commit().setMessage("readme").setCommitter("sshd", "sshd@apache.org").call();
        git.push().call();

        git.pull().setRebase(true).call();

        sshd.stop();
    }
View Full Code Here

   @Test
   public void testCreateRepo() throws Exception
   {
      Project project = projectFactory.createTempProject();

      Git repo = gitUtils.init(project.getRootDirectory());
      Assert.assertTrue(repo.getRepository().getDirectory().exists());
   }
View Full Code Here

   @Test
   public void testGetTags() throws Exception
   {
      Project project = projectFactory.createTempProject();

      Git repo = gitUtils.init(project.getRootDirectory());
      Map<String, Ref> tags = repo.getRepository().getTags();
      Assert.assertTrue(tags.isEmpty());
   }
View Full Code Here

      List<Ref> branches = null;
      String[] commitMsgs = { "initial commit", "First commit" };
      String[] branchNames = { "master", "branch_two" };

      Project project = projectFactory.createTempProject();
      Git repo = gitUtils.init(project.getRootDirectory());

      gitUtils.addAll(repo);
      gitUtils.commitAll(repo, commitMsgs[0]);

      branches = gitUtils.getLocalBranches(repo);
View Full Code Here

   @Test
   public void shouldReturnOneLogEntryForSingleCommit() throws Exception
   {
      Project project = projectFactory.createTempProject();
      Git repo = gitUtils.init(project.getRootDirectory());
      String commitMsg = "First commit";

      gitUtils.addAll(repo);
      gitUtils.commitAll(repo, "initial commit");
View Full Code Here

   {
      boolean isCreated = false;
      String[] commitMsgs = { "initial commit", "First commit", "Second commit" };

      Project project = projectFactory.createTempProject();
      Git repo = gitUtils.init(project.getRootDirectory());

      gitUtils.addAll(repo);
      gitUtils.commitAll(repo, commitMsgs[0]);

      FileResource<?> file1 = project.getRootDirectory().getChild("test.txt").reify(FileResource.class);
View Full Code Here

   @Test
   public void shouldThrowNoHeadExceptionWhenRepoHasNoCommits() throws Exception
   {
      Project project = projectFactory.createTempProject();
      Git repo = gitUtils.init(project.getRootDirectory());

      try
      {
         gitUtils.getLogForCurrentBranch(repo);
         Assert.fail("Expected " + NoHeadException.class);
View Full Code Here

   {
      boolean isCreated = false;
      String[] commitMsgs = { "initial commit", "First commit" };

      Project project = projectFactory.createTempProject();
      Git repo = gitUtils.init(project.getRootDirectory());

      gitUtils.addAll(repo);
      gitUtils.commitAll(repo, commitMsgs[0]);

      FileResource<?> file1 = project.getRootDirectory().getChild("test.txt").reify(FileResource.class);
      isCreated = file1.createNewFile();
      Assert.assertTrue("file 1 was not created", isCreated);
      file1.setContents("Foo bar baz contents");

      gitUtils.addAll(repo);
      gitUtils.stashCreate(repo);

      Assert.assertTrue("should contain one stash", repo.stashList().call().iterator().hasNext());

      gitUtils.stashApply(repo);

      gitUtils.addAll(repo);
      gitUtils.commit(repo, commitMsgs[1]);

      gitUtils.stashDrop(repo);

      List<String> logs = gitUtils.getLogForCurrentBranch(repo);
      Collections.reverse(logs); // git-log shows logs in DESC order

      Assert.assertNotNull("log should not be null", logs);
      Assert.assertEquals("log should contain two items", 2, logs.size());
      Assert.assertEquals("commit messages should be the same", commitMsgs[0], logs.get(0));
      Assert.assertEquals("commit messages should be the same", commitMsgs[1], logs.get(1));

      Assert.assertFalse("should contain no stashes", repo.stashList().call().iterator().hasNext());
   }
View Full Code Here

      String[] branchNames = { "master", "branch_two" };
      String[] files = { "test1.txt", "test2.txt" };

      Project project = projectFactory.createTempProject();
      Git repo = gitUtils.init(project.getRootDirectory());

      gitUtils.addAll(repo);
      gitUtils.commitAll(repo, "initial commit");

      repo.branchCreate().setName(branchNames[1]).call();

      FileResource<?> file0 = project.getRootDirectory().getChild(files[0]).reify(FileResource.class);
      file0.createNewFile();
      gitUtils.add(repo, files[0]);
      gitUtils.commit(repo, "file added on " + branchNames[0]);

      gitUtils.switchBranch(repo, branchNames[1]);

      FileResource<?> file1 = project.getRootDirectory().getChild(files[1]).reify(FileResource.class);
      file1.createNewFile();
      gitUtils.add(repo, files[1]);
      gitUtils.commit(repo, "file added on " + branchNames[1]);

      gitUtils.getLogForCurrentBranch(repo);

      gitUtils.switchBranch(repo, branchNames[0]);
      Ref branch2Ref = repo.getRepository().getRef(branchNames[1]);
      gitUtils.cherryPick(repo, branch2Ref);

      // assert file2 exists
      Assert.assertTrue("file from cherry picked commit should exist", project.getRootDirectory().getChild(files[1])
               .exists());
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.api.Git

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.