Example usage for org.eclipse.jgit.lib Constants MASTER

List of usage examples for org.eclipse.jgit.lib Constants MASTER

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants MASTER.

Prototype

String MASTER

To view the source code for org.eclipse.jgit.lib Constants MASTER.

Click Source Link

Document

Default main branch name

Usage

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

License:Open Source License

/**
 * Get tree id with null path// ww w .  j a  va2s  .c  om
 *
 * @throws IOException
 */
@Test(expected = IllegalArgumentException.class)
public void getIdNullPath2() throws IOException {
    TreeUtils.getId(new FileRepository(testRepo), Constants.MASTER, null);
}

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

License:Open Source License

/**
 * Get tree id with empty path//  ww w.j  a v  a 2 s .c  om
 *
 * @throws IOException
 */
@Test(expected = IllegalArgumentException.class)
public void getIdEmptyPath2() throws IOException {
    TreeUtils.getId(new FileRepository(testRepo), Constants.MASTER, "");
}

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

License:Open Source License

/**
 * Get id with revision/*www . j  a  va  2s . c  o m*/
 *
 * @throws Exception
 */
@Test
public void getIdWithRevision() throws Exception {
    Repository repo = new FileRepository(testRepo);
    RevCommit commit = add("d1/f1.txt", "content");
    assertNull(TreeUtils.getId(repo, Constants.MASTER, "d2/f1.txt"));
    assertNull(TreeUtils.getId(repo, Constants.MASTER, "d1/f1.txt"));
    ObjectId treeId = TreeUtils.getId(repo, Constants.MASTER, "d1");
    assertNotNull(treeId);
    assertFalse(treeId.equals(commit.getTree()));
    assertNull(BlobUtils.getId(repo, commit, "d1"));
    assertFalse(treeId.equals(BlobUtils.getId(repo, commit, "d1/f1.txt")));
}

From source file:org.jboss.as.controller.persistence.AbstractGitPersistenceResourceTestCase.java

License:Apache License

protected List<String> listCommits(Repository repository) throws IOException, GitAPIException {
    try (Git git = new Git(repository)) {
        return listCommits(git, Constants.MASTER);
    }//from w  w  w  .  j ava  2  s.c  om
}

From source file:org.jboss.as.test.manualmode.management.persistence.AbstractGitRepositoryTestCase.java

License:Apache License

protected List<String> listFilesInCommit(Repository repository) throws IOException, GitAPIException {
    List<String> result = new ArrayList<>();
    try (Git git = new Git(repository)) {
        RevCommit commit = git.log().add(git.getRepository().resolve(Constants.MASTER)).call().iterator()
                .next();//  w w  w. j  av  a 2  s.c  om
        if (commit.getParentCount() > 0) {
            try (TreeWalk treeWalk = new TreeWalk(repository)) {
                treeWalk.addTree(commit.getParent(0).getTree());
                treeWalk.addTree(commit.getTree());
                treeWalk.setRecursive(true);
                List<DiffEntry> diff = DiffEntry.scan(treeWalk, false, null);
                for (DiffEntry diffEntry : diff) {
                    if (diffEntry.getChangeType() == DiffEntry.ChangeType.DELETE) {
                        result.add("-" + diffEntry.getOldPath());
                    } else {
                        result.add(diffEntry.getNewPath());
                    }
                }
            }
        }
    }
    Collections.sort(result);
    return result;
}

From source file:org.jboss.as.test.manualmode.management.persistence.RemoteGitRepositoryTestCase.java

License:Apache License

/**
 * Start server with parameter --git-repo=file:///my_repo/test/.git
 *//*from ww w.j a  v a 2  s.  c  o  m*/
@Test
public void startGitRepoRemoteTest() throws Exception {
    // start with remote repository containing configuration (--git-repo=file:///my_repo/test/.git)
    container.startGitBackedConfiguration(
            "file://" + remoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString(), Constants.MASTER,
            null);
    Assert.assertTrue("Directory not found " + getDotGitDir(), Files.exists(getDotGitDir()));
    Assert.assertTrue("File not found " + getDotGitIgnore(), Files.exists(getDotGitIgnore()));
    List<String> commits = listCommits(remoteRepository);
    Assert.assertEquals(1, commits.size());
    addSystemProperty();
    publish(null);
    commits = listCommits(remoteRepository);
    Assert.assertEquals(3, commits.size());

    // create branch in remote repo and change master for next test
    try (Git git = new Git(remoteRepository)) {
        git.checkout().setName("my_branch").setCreateBranch(true).call();
    }
    removeSystemProperty();
    publish(null);
    container.stop();
    closeRepository();

    // start with remote repository and branch containing configuration
    // (--git-repo=file:///my_repo/test/.git --git-branch=my_branch)
    container.startGitBackedConfiguration(
            "file://" + remoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString(), "my_branch", null);
    Assert.assertTrue("Directory not found " + getDotGitDir(), Files.exists(getDotGitDir()));
    Assert.assertTrue("File not found " + getDotGitIgnore(), Files.exists(getDotGitIgnore()));
    try {
        addSystemProperty();
        Assert.fail("Operation should have failed");
    } catch (UnsuccessfulOperationException uoe) {
        Assert.assertTrue(uoe.getMessage().contains("WFLYCTL0212"));
    }
}

From source file:org.jboss.as.test.manualmode.management.persistence.RemoteGitRepositoryTestCase.java

License:Apache License

/**
 * Start server with parameter --git-repo=file:///my_repo/test/.git
 *//*from   w w  w.j av  a2s.  com*/
@Test
public void historyAndManagementOperationsTest() throws Exception {
    container.startGitBackedConfiguration(
            "file://" + remoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString(), Constants.MASTER,
            null);
    Assert.assertTrue("Directory not found " + getDotGitDir(), Files.exists(getDotGitDir()));
    Assert.assertTrue("File not found " + getDotGitIgnore(), Files.exists(getDotGitIgnore()));
    repository = createRepository();

    int expectedNumberOfCommits = 2;

    // start => initial commit
    List<String> commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Adding .gitignore", commits.get(0));
    Assert.assertEquals("Repository initialized", commits.get(1));
    List<String> paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 1, paths.size());

    // change configuration => commit
    addSystemProperty();
    expectedNumberOfCommits++;
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));
    paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 1, paths.size());
    Assert.assertEquals("configuration/standalone.xml", paths.get(0));

    // deploy deployment => commit
    deployEmptyDeployment();
    expectedNumberOfCommits++;
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));
    paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 2, paths.size());
    Assert.assertEquals("configuration/standalone.xml", paths.get(0));
    String contentPath = paths.get(1);
    Assert.assertTrue(contentPath.startsWith("data/content/") && contentPath.endsWith("/content"));

    // undeploy deployment (/deployment=name:undeploy) => commited
    undeployDeployment();
    expectedNumberOfCommits++;
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));
    paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 1, paths.size());
    Assert.assertEquals("configuration/standalone.xml", paths.get(0));

    // exploded deployment => commited
    explodeDeployment();
    expectedNumberOfCommits++;
    commits = listCommits(repository);
    Assert.assertEquals(Arrays.toString(commits.toArray()), expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));
    paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 3, paths.size());
    Assert.assertEquals("-" + contentPath, paths.get(0));
    Assert.assertEquals("configuration/standalone.xml", paths.get(1));
    String contentFile = paths.get(2);
    Assert.assertNotEquals(contentPath, contentFile);
    Assert.assertTrue(contentFile.startsWith("data/content/") && contentFile.endsWith("/content/file"));

    // exploded deployment - add content => commited
    addContentToDeployment();
    expectedNumberOfCommits++;
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));
    paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 4, paths.size());
    Assert.assertEquals("configuration/standalone.xml", paths.get(1));
    Assert.assertEquals("-" + contentFile, paths.get(0));
    contentFile = paths.get(2);
    String contentProperties = paths.get(3);
    Assert.assertNotEquals(contentPath, contentFile);
    Assert.assertNotEquals(contentPath, contentProperties);
    Assert.assertTrue(contentFile.startsWith("data/content/") && contentFile.endsWith("/content/file"));
    Assert.assertTrue(contentProperties.startsWith("data/content/")
            && contentProperties.endsWith("/content/test.properties"));

    // exploded deployment - remove content => commited
    removeContentFromDeployment();
    expectedNumberOfCommits++;
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));
    paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 4, paths.size());
    Assert.assertEquals("-" + contentFile, paths.get(0));
    Assert.assertEquals("-" + contentProperties, paths.get(1));
    Assert.assertEquals("configuration/standalone.xml", paths.get(2));
    contentFile = paths.get(3);
    Assert.assertTrue(contentFile.startsWith("data/content/") && contentFile.endsWith("/content/file"));

    // :clean-obsolete-content
    // remove deployment => commit
    removeDeployment();
    expectedNumberOfCommits++;
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));
    paths = listFilesInCommit(repository);
    Assert.assertEquals(Arrays.toString(paths.toArray()), 2, paths.size());
    Assert.assertEquals("-" + contentFile, paths.get(0));
    Assert.assertEquals("configuration/standalone.xml", paths.get(1));
    // :clean-obsolete-content
    // deployment-overlay

    // there are no tags
    List<String> tags = listTags(repository);
    Assert.assertEquals(0, tags.size());

    // :take-snapshot => tag = timestamp
    LocalDateTime snapshot = LocalDateTime.now();
    takeSnapshot(null, null);
    tags = listTags(repository);
    Assert.assertEquals(1, tags.size());
    verifyDefaultSnapshotString(snapshot, tags.get(0));
    // this snapshot is not expected to have commit, as there is no uncommited remove of content data
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("Storing configuration", commits.get(0));

    // :take-snapshot(name=foo) => success, tag=foo
    takeSnapshot("foo", null);
    tags = listTags(repository);
    Assert.assertEquals(2, tags.size());
    // there should be two tags, from this and previous snapshot
    Assert.assertEquals("foo", tags.get(1));
    // this should be the same commit as with previous snapshot
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());

    // :take-snapshot(name=foo) => fail, tag already exists
    try {
        takeSnapshot("foo", null);
        Assert.fail("Operation should have failed");
    } catch (UnsuccessfulOperationException uoe) {
        // good
        Assert.assertTrue(uoe.getMessage().contains("WFLYCTL0455"));
    }

    // :take-snapshot(description=bar) => tag = timestamp, commit msg=bar
    snapshot = LocalDateTime.now();
    takeSnapshot(null, "bar");
    expectedNumberOfCommits++;
    tags = listTags(repository);
    Assert.assertEquals(3, tags.size());
    // tags are ordered alphabetically, so we want second with default name
    verifyDefaultSnapshotString(snapshot, tags.get(1));
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("bar", commits.get(0));

    // :take-snapshot(name=fooo, description=barbar) => success, tag=fooo, commit msg=bar
    takeSnapshot("fooo", "bar");
    expectedNumberOfCommits++;
    tags = listTags(repository);
    Assert.assertEquals(4, tags.size());
    // fooo is alphabetically last
    Assert.assertEquals("fooo", tags.get(3));
    commits = listCommits(repository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("bar", commits.get(0));

    // :take-snapshot(name=fooo, description=bar) => fail
    try {
        takeSnapshot("fooo", "bar");
        Assert.fail("Operation should have failed");
    } catch (UnsuccessfulOperationException uoe) {
        // good
        Assert.assertTrue(uoe.getMessage().contains("WFLYCTL0455"));
    }

    // :publish-configuration => push to origin
    commits = listCommits(remoteRepository);
    Assert.assertEquals(1, commits.size());
    Assert.assertEquals("Repository initialized", commits.get(0));
    publish(null);
    commits = listCommits(remoteRepository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("bar", commits.get(0));

    // :publish-configuration(location=empty) => push to empty)
    publish("empty");
    tags = listTags(emptyRemoteRepository);
    Assert.assertEquals(4, tags.size());
    Assert.assertEquals("fooo", tags.get(3));
    commits = listCommits(emptyRemoteRepository);
    Assert.assertEquals(expectedNumberOfCommits, commits.size());
    Assert.assertEquals("bar", commits.get(0));
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

/**
 * Returns <code>true</code> if the given branch in the given repository has
 * local commits that were not pushed to its remote yet.
 * /*from   w w  w.j a  va 2  s. com*/
 * @param repository
 * @param branchName
 * @return
 * @throws IOException
 */
public static boolean hasCommitsToBePushed(Repository repository) throws IOException {
    BranchTrackingStatus status = BranchTrackingStatus.of(repository, Constants.MASTER);
    if (status == null) {
        return false;
    }
    return status.getAheadCount() > 0;
}

From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java

License:Open Source License

public TestRepository cloneRepository(File path)
        throws URISyntaxException, InvocationTargetException, InterruptedException, IOException {
    URIish uri = new URIish("file:///" + repository.getDirectory().toString());
    CloneOperation clop = new CloneOperation(uri, true, null, path, Constants.R_HEADS + Constants.MASTER,
            Constants.DEFAULT_REMOTE_NAME, 0);
    clop.run(null);/*from   ww w .j ava 2 s . co  m*/
    RepositoryCache repositoryCache = Activator.getDefault().getRepositoryCache();
    Repository clonedRepository = repositoryCache.lookupRepository(new File(path, Constants.DOT_GIT));
    return new TestRepository(clonedRepository);
}

From source file:org.jenkinsci.git.FetchOperationTest.java

License:Open Source License

/**
 * Test fetching single commit/*from  w w  w  . ja va 2s .c o m*/
 *
 * @throws Exception
 */
@Test
public void fetchSingleCommit() throws Exception {
    git.add("file.txt", "a");
    File dir = git.tempDirectory();
    BuildRepository repo = new BuildRepository(git.repo().getDirectory().toURI().toString(),
            Constants.R_HEADS + Constants.MASTER, null);
    CloneOperation clone = new CloneOperation(repo);
    Repository cloned = clone.invoke(dir, null);
    assertNotNull(cloned);
    RevCommit commit2 = git.add("file1.txt", "b");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StreamProgressMonitor monitor = new StreamProgressMonitor(new PrintStream(out));
    FetchOperation fetch = new FetchOperation(repo, cloned, monitor);
    RevCommit fetched = fetch.call();
    assertEquals(commit2, fetched);
    assertTrue(out.toString().length() > 0);
}