Example usage for org.eclipse.jgit.api Git open

List of usage examples for org.eclipse.jgit.api Git open

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git open.

Prototype

public static Git open(File dir) throws IOException 

Source Link

Document

Open repository

Usage

From source file:org.fusesource.fabric.itests.basic.git.ExternalGitTest.java

License:Apache License

@Test
public void testCreateProfilesMixedWithVersion() throws Exception {
    String testZkProfilebase = "zkprofile";
    String testGitProfilebase = "gitprofile";
    System.err.println(executeCommand("fabric:create -n"));
    //Set<Container> containers = ContainerBuilder.create(1, 1).withName("child").assertProvisioningResult().build();
    String gitRepoUrl = GitUtils.getMasterUrl(getCurator());
    assertNotNull(gitRepoUrl);// w w  w.  j a va2s  .  com
    GitUtils.waitForBranchUpdate(getCurator(), "1.0");

    Git.cloneRepository().setURI(gitRepoUrl).setCloneAllBranches(true).setDirectory(testrepo)
            .setCredentialsProvider(getCredentialsProvider()).call();
    Git git = Git.open(testrepo);
    GitUtils.configureBranch(git, "origin", gitRepoUrl, "1.0");
    git.fetch().setCredentialsProvider(getCredentialsProvider());
    GitUtils.checkoutBranch(git, "origin", "1.0");

    //Check that the default profile exists
    assertTrue(new File(testrepo, "fabric/profiles/default.profile").exists());

    FabricService fabricService = getFabricService();
    for (int v = 0; v < 2; v++) {
        //Create test profile
        for (int i = 1; i < 2; i++) {
            String gitProfile = testGitProfilebase + v + "p" + i;
            String zkProfile = testZkProfilebase + v + "p" + i;
            createAndTestProfileInGit(git, "1." + v, gitProfile);
            createAndTestProfileInDataStore(git, "1." + v, zkProfile);
        }
    }
}

From source file:org.fusesource.fabric.itests.basic.git.GitBridgeTest.java

License:Apache License

@Ignore
@Test//from  w w w .  j a  va 2s .  c  o m
public void testCreateProfileInGit() throws Exception {
    String testProfileNameBase = "mytestprofile-";
    System.err.println(executeCommand("fabric:create -n"));
    System.err.println(executeCommand("features:install fabric-git"));
    //Set<Container> containers = ContainerBuilder.create(1, 1).withName("child").assertProvisioningResult().build();
    String gitRepoUrl = GitUtils.getMasterUrl(getCurator());
    assertNotNull(gitRepoUrl);
    GitUtils.waitForBranchUpdate(getCurator(), "1.0");

    Git.cloneRepository().setURI(gitRepoUrl).setCloneAllBranches(true).setDirectory(testrepo)
            .setCredentialsProvider(getCredentialsProvider()).call();
    Git git = Git.open(testrepo);
    GitUtils.configureBranch(git, "origin", gitRepoUrl, "1.0");
    git.fetch().setCredentialsProvider(getCredentialsProvider());
    GitUtils.checkoutBranch(git, "origin", "1.0");

    //Check that the default profile exists
    assertTrue(new File(testrepo, "default").exists());

    //Create test profile
    for (int i = 1; i <= 5; i++) {
        String testProfileName = testProfileNameBase + i;
        createAndTestProfileInGit(git, "1.0", testProfileName);
    }
}

From source file:org.fusesource.fabric.itests.basic.git.GitBridgeTest.java

License:Apache License

@Ignore
@Test/*from  w  w  w.  ja  va 2 s  . co m*/
public void testCreateProfileInZk() throws Exception {
    String testProfileNameBase = "mytestprofile-";
    System.err.println(executeCommand("fabric:create -n"));
    System.err.println(executeCommand("features:install fabric-git"));
    //Set<Container> containers = ContainerBuilder.create(1, 1).withName("child").assertProvisioningResult().build();
    String gitRepoUrl = GitUtils.getMasterUrl(getCurator());
    assertNotNull(gitRepoUrl);
    GitUtils.waitForBranchUpdate(getCurator(), "1.0");

    Git.cloneRepository().setURI(gitRepoUrl).setCloneAllBranches(true).setDirectory(testrepo)
            .setCredentialsProvider(getCredentialsProvider()).call();
    Git git = Git.open(testrepo);
    GitUtils.configureBranch(git, "origin", gitRepoUrl, "1.0");
    git.fetch().setCredentialsProvider(getCredentialsProvider());
    GitUtils.checkoutBranch(git, "origin", "1.0");

    //Check that the default profile exists
    assertTrue(new File(testrepo, "default").exists());

    FabricService fabricService = getFabricService();
    //Create test profile
    for (int i = 1; i <= 5; i++) {
        String testProfileName = testProfileNameBase + i;
        createAndTestProfileInZooKeeper(git, "1.0", testProfileName);
    }
}

From source file:org.fusesource.fabric.itests.basic.git.GitBridgeTest.java

License:Apache License

@Ignore
@Test//from  w  w w. j a v a 2  s  . co m
public void testCreateProfilesMixed() throws Exception {
    String testZkProfilebase = "zkprofile-";
    String testGitProfilebase = "gitprofile-";
    System.err.println(executeCommand("fabric:create -n"));
    System.err.println(executeCommand("features:install fabric-git"));
    //Set<Container> containers = ContainerBuilder.create(1, 1).withName("child").assertProvisioningResult().build();
    String gitRepoUrl = GitUtils.getMasterUrl(getCurator());
    assertNotNull(gitRepoUrl);
    GitUtils.waitForBranchUpdate(getCurator(), "1.0");

    Git.cloneRepository().setURI(gitRepoUrl).setCloneAllBranches(true).setDirectory(testrepo)
            .setCredentialsProvider(getCredentialsProvider()).call();
    Git git = Git.open(testrepo);
    GitUtils.configureBranch(git, "origin", gitRepoUrl, "1.0");
    git.fetch().setCredentialsProvider(getCredentialsProvider());
    GitUtils.checkoutBranch(git, "origin", "1.0");

    //Check that the default profile exists
    assertTrue(new File(testrepo, "default").exists());

    FabricService fabricService = getFabricService();
    //Create test profile
    for (int i = 1; i <= 5; i++) {
        String gitProfile = testGitProfilebase + i;
        String zkProfile = testZkProfilebase + i;
        createAndTestProfileInGit(git, "1.0", gitProfile);
        createAndTestProfileInZooKeeper(git, "1.0", zkProfile);
    }
}

From source file:org.fusesource.fabric.itests.basic.git.GitBridgeTest.java

License:Apache License

@Test
public void testCreateProfilesMixedWithVersion() throws Exception {
    String testZkProfilebase = "zkprofile-";
    String testGitProfilebase = "gitprofile-";
    System.err.println(executeCommand("fabric:create -n"));
    System.err.println(executeCommand("features:install fabric-git"));
    //Set<Container> containers = ContainerBuilder.create(1, 1).withName("child").assertProvisioningResult().build();
    String gitRepoUrl = GitUtils.getMasterUrl(getCurator());
    assertNotNull(gitRepoUrl);/*from   www .j  a  v  a 2s. c o  m*/
    GitUtils.waitForBranchUpdate(getCurator(), "1.0");

    Git.cloneRepository().setURI(gitRepoUrl).setCloneAllBranches(true).setDirectory(testrepo)
            .setCredentialsProvider(getCredentialsProvider()).call();
    Git git = Git.open(testrepo);
    GitUtils.configureBranch(git, "origin", gitRepoUrl, "1.0");
    git.fetch().setCredentialsProvider(getCredentialsProvider());
    GitUtils.checkoutBranch(git, "origin", "1.0");

    //Check that the default profile exists
    assertTrue(new File(testrepo, "default").exists());

    FabricService fabricService = getFabricService();
    for (int v = 0; v < 3; v++) {
        //Create test profile
        for (int i = 1; i <= 3; i++) {
            String gitProfile = testGitProfilebase + v + "-" + i;
            String zkProfile = testZkProfilebase + v + "-" + i;
            createAndTestProfileInGit(git, "1." + v, gitProfile);
            createAndTestProfileInZooKeeper(git, "1." + v, zkProfile);
        }
    }
}

From source file:org.fusesource.fabric.itests.basic.git.GitBridgeTest.java

License:Apache License

public void testWithProfiles() throws Exception {
    String testProfileNameBase = "mytestprofile-";
    System.err.println(executeCommand("fabric:create -n"));
    Set<Container> containers = ContainerBuilder.create(1, 1).withName("child").assertProvisioningResult()
            .build();//from   w  w w. j a v  a 2 s .  c  om
    String gitRepoUrl = GitUtils.getMasterUrl(getCurator());

    GitUtils.waitForBranchUpdate(getCurator(), "1.0");

    Git.cloneRepository().setURI(gitRepoUrl).setCloneAllBranches(true).setDirectory(testrepo)
            .setCredentialsProvider(getCredentialsProvider()).call();
    Git git = Git.open(testrepo);
    GitUtils.configureBranch(git, "origin", gitRepoUrl, "1.0");
    git.fetch().setCredentialsProvider(getCredentialsProvider());
    GitUtils.checkoutBranch(git, "origin", "1.0");

    //Check that the default profile exists
    assertTrue(new File(testrepo, "default").exists());

    //Create test profile
    for (int i = 1; i <= 3; i++) {
        String testProfileName = testProfileNameBase + i;
        System.err.println("Create test profile:" + testProfileName + " in zookeeper");
        getFabricService().getVersion("1.0").createProfile(testProfileName);
        GitUtils.waitForBranchUpdate(getCurator(), "1.0");
        git.pull().setRebase(true).setCredentialsProvider(getCredentialsProvider()).call();
        //Check that a newly created profile exists
        assertTrue(new File(testrepo, testProfileName).exists());
        //Delete test profile
        System.err.println("Delete test profile:" + testProfileName + " in git.");
        git.rm().addFilepattern(testProfileName).call();
        git.commit().setMessage("Delete " + testProfileName).call();
        git.push().setCredentialsProvider(getCredentialsProvider()).setRemote("origin").call();
        GitUtils.waitForBranchUpdate(getCurator(), "1.0");
        Thread.sleep(5000);
        assertFalse(new File(testrepo, testProfileName).exists());
        assertNull(getCurator().checkExists()
                .forPath(ZkPath.CONFIG_VERSIONS_PROFILE.getPath("1.0", testProfileName)));

        //Create the test profile in git
        System.err.println("Create test profile:" + testProfileName + " in git.");
        File testProfileDir = new File(testrepo, testProfileName);
        testProfileDir.mkdirs();
        File testProfileConfig = new File(testProfileDir, "org.fusesource.fabric.agent.properties");
        testProfileConfig.createNewFile();
        Files.writeToFile(testProfileConfig, "", Charset.defaultCharset());
        git.add().addFilepattern(testProfileName).call();
        RevCommit commit = git.commit().setMessage("Create " + testProfileName).call();
        FileTreeIterator fileTreeItr = new FileTreeIterator(git.getRepository());
        IndexDiff indexDiff = new IndexDiff(git.getRepository(), commit.getId(), fileTreeItr);
        System.out.println(indexDiff.getChanged());
        System.out.println(indexDiff.getAdded());
        git.push().setCredentialsProvider(getCredentialsProvider()).setRemote("origin").call();
        GitUtils.waitForBranchUpdate(getCurator(), "1.0");
        //Check that it has been bridged in zookeeper
        Thread.sleep(15000);
        assertNotNull(getCurator().checkExists()
                .forPath(ZkPath.CONFIG_VERSIONS_PROFILE.getPath("1.0", testProfileName)));
    }
}

From source file:org.gitective.tests.GitTestCase.java

License:Open Source License

/**
 * Create branch with name and checkout//from  w  ww  .  ja va2  s .co  m
 *
 * @param repo
 * @param name
 * @return branch ref
 * @throws Exception
 */
protected Ref branch(File repo, String name) throws Exception {
    Git git = Git.open(repo);
    git.branchCreate().setName(name).call();
    return checkout(repo, name);
}

From source file:org.gitective.tests.GitTestCase.java

License:Open Source License

/**
 * Checkout branch//from  w  w  w.  j  a v  a 2s  . co  m
 *
 * @param repo
 * @param name
 * @return branch ref
 * @throws Exception
 */
protected Ref checkout(File repo, String name) throws Exception {
    Git git = Git.open(repo);
    Ref ref = git.checkout().setName(name).call();
    assertNotNull(ref);
    return ref;
}

From source file:org.gitective.tests.GitTestCase.java

License:Open Source License

/**
 * Create tag with name//from w w w  .  ja v a 2s .  c  o  m
 *
 * @param repo
 * @param name
 * @return tag ref
 * @throws Exception
 */
protected Ref tag(File repo, String name) throws Exception {
    Git git = Git.open(repo);
    git.tag().setName(name).setMessage(name).call();
    Ref tagRef = git.getRepository().getTags().get(name);
    assertNotNull(tagRef);
    return tagRef;
}

From source file:org.gitective.tests.GitTestCase.java

License:Open Source License

/**
 * Add file to test repository/*from  w  ww.j av  a  2s  .  c  o m*/
 *
 * @param repo
 * @param path
 * @param content
 * @param message
 * @return commit
 * @throws Exception
 */
protected RevCommit add(File repo, String path, String content, String message) throws Exception {
    File file = new File(repo.getParentFile(), path);
    if (!file.getParentFile().exists())
        assertTrue(file.getParentFile().mkdirs());
    if (!file.exists())
        assertTrue(file.createNewFile());
    PrintWriter writer = new PrintWriter(file);
    if (content == null)
        content = "";
    try {
        writer.print(content);
    } finally {
        writer.close();
    }
    Git git = Git.open(repo);
    git.add().addFilepattern(path).call();
    RevCommit commit = git.commit().setOnly(path).setMessage(message).setAuthor(author).setCommitter(committer)
            .call();
    assertNotNull(commit);
    return commit;
}