Examples of Git


Examples of org.eclipse.jgit.api.Git

      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

Examples of org.eclipse.jgit.api.Git

      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.cherryPickNoMerge(repo, branch2Ref);

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

Examples of org.eclipse.jgit.api.Git

      List<String> log = null;
      String[] branchNames = { "master" };
      String[] files = { "test1.txt", "test2.txt" };

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

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

      FileResource<?> file0 = project.getRootDirectory().getChild(files[0]).reify(FileResource.class);
View Full Code Here

Examples of org.eclipse.jgit.api.Git

      // create new branch
      // verify branch exists

      String testBranchName = "testBranch";
      Project project = projectFactory.createTempProject();
      Git repo = gitUtils.init(project.getRootDirectory());

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

      Ref testBranch = gitUtils.createBranch(repo, testBranchName);
View Full Code Here

Examples of org.eclipse.jgit.api.Git

      String[] files = { "test1.txt" };
      List<String> commits = null;
      CherryPickResult cherryPickResult = null;

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

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

      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]);

      commits = gitUtils.getLogForCurrentBranch(repo);
      Assert.assertEquals("Wrong number of commits in log", 2, commits.size());
      cherryPickResult = gitUtils.cherryPickNoMerge(repo, repo.getRepository().getRef(branchNames[0]));
      Assert.assertEquals("Wrong cherrypick status", CherryPickResult.CherryPickStatus.OK, cherryPickResult.getStatus());
      gitUtils.resetHard(repo, "HEAD^1");

      commits = gitUtils.getLogForCurrentBranch(repo);
      Assert.assertEquals("Wrong number of commits in log", 1, commits.size());
      try {        
         gitUtils.cherryPickNoMerge(repo, repo.getRepository().getRef(branchNames[0]));
         Assert.fail("Expected exception: " + CantMergeCommitException.class);
      } catch (CantMergeCommitException cmce)
      {
         // Expected
      }
View Full Code Here

Examples of org.eclipse.jgit.api.Git

   }

   public static Git git(DirectoryResource dir) throws IOException
   {
      RepositoryBuilder db = new RepositoryBuilder().findGitDir(dir.getUnderlyingResourceObject());
      return new Git(db.build());
   }
View Full Code Here

Examples of org.eclipse.jgit.api.Git

      }
   }

   private void cloneTo(DirectoryResource projectRoot) throws GitAPIException, IOException
   {
      Git git = null;
      try
      {
         git = gitUtils.clone(projectRoot, url.getValue().getFullyQualifiedName());
         if (ref.hasValue())
         {
            String refName = ref.getValue();
            String currentBranch = git.getRepository().getBranch();
            // No need to checkout if the branch name is the same
            if (!currentBranch.equals(refName))
            {
               git.checkout().
                        setCreateBranch(true).
                        setName(refName).
                        setUpstreamMode(SetupUpstreamMode.TRACK).
                        setStartPoint("origin/" + refName).
                        call();
View Full Code Here

Examples of org.eclipse.jgit.api.Git

   @Override
   public Git clone(final DirectoryResource dir, final String repoUri) throws GitAPIException
   {
      CloneCommand clone = Git.cloneRepository().setURI(repoUri)
               .setDirectory(dir.getUnderlyingResourceObject());
      Git git = clone.call();
      return git;
   }
View Full Code Here

Examples of org.eclipse.jgit.api.Git

   @Override
   public Git git(final DirectoryResource dir) throws IOException
   {
      RepositoryBuilder db = new RepositoryBuilder().findGitDir(dir.getUnderlyingResourceObject());
      return new Git(db.build());
   }
View Full Code Here

Examples of org.eclipse.jgit.api.Git

   {
      FileResource<?> gitDir = dir.getChildDirectory(".git").reify(FileResource.class);
      gitDir.mkdirs();

      RepositoryBuilder db = new RepositoryBuilder().setGitDir(gitDir.getUnderlyingResourceObject()).setup();
      Git git = new Git(db.build());
      git.getRepository().create();
      return git;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.