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

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

Introduction

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

Prototype

String DOT_GIT

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

Click Source Link

Document

Default name for the Git repository directory

Usage

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 .ja  v  a  2s  .  c  o  m*/
@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.forge.git.Clone.java

License:Eclipse Distribution License

public void run(File projectDir, String sourceUri) throws IOException {
    try {//w w  w  .  j  av  a2 s .c  o m
        final URIish uri = new URIish(sourceUri);
        File gitdir = new File(projectDir, Constants.DOT_GIT);
        db = new FileRepository(gitdir);
        db.create();
        final FileBasedConfig dstcfg = db.getConfig();
        dstcfg.setBoolean("core", null, "bare", false);
        dstcfg.save();

        saveRemote(uri);
        final FetchResult r = runFetch();
        final Ref branch = guessHEAD(r);
        doCheckout(branch);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Failed to parse remote repository URI", e);
    }
}

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

License:Open Source License

/**
 * Returns <code>true</code> if the given project exists and has a .git
 * folder in it./*from   w  ww.j  a  va 2  s  .c  o m*/
 * 
 * @param project
 * @return
 */
public static boolean hasDotGitFolder(IProject project) {
    if (project == null || !project.exists()) {
        return false;
    }
    return new File(project.getLocation().toOSString(), Constants.DOT_GIT).exists();
}

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

License:Open Source License

public static File getRepositoryPathFor(IProject project) {
    return new File(project.getLocationURI().getPath(), Constants.DOT_GIT);
}

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 w ww  .j a v a2s.c om*/
    RepositoryCache repositoryCache = Activator.getDefault().getRepositoryCache();
    Repository clonedRepository = repositoryCache.lookupRepository(new File(path, Constants.DOT_GIT));
    return new TestRepository(clonedRepository);
}

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

License:Open Source License

public static File createGitDir(TestProject testProject) throws IOException {
    return new File(testProject.getProject().getLocation().toFile(), Constants.DOT_GIT);
}

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

License:Open Source License

/**
 * Test cloning a local repository/*from   w  ww . j av a2  s .c o  m*/
 * 
 * @throws Exception
 */
@Test
public void cloneRepository() throws Exception {
    Repository existing = git.repo();
    RevCommit commit = git.add("file.txt", "abcd");
    BuildRepository repo = new BuildRepository(existing.getDirectory().toURI().toString(), "master", null);
    File dir = git.tempDirectory();
    CloneOperation op = new CloneOperation(repo);
    Repository cloned = op.invoke(dir, null);
    assertNotNull(cloned);
    assertFalse(existing.getDirectory().equals(cloned.getDirectory()));
    assertTrue(new File(dir, Constants.DOT_GIT).exists());
    assertNotNull(CommitUtils.getCommit(cloned, commit));
}

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

License:Open Source License

/**
 * Test cloning into a subdirectory/*from  w w  w.ja  v a 2 s .co m*/
 * 
 * @throws Exception
 */
@Test
public void cloneIntoSubDirectory() throws Exception {
    Repository existing = git.repo();
    RevCommit commit = git.add("file.txt", "abcd");
    BuildRepository repo = new BuildRepository(existing.getDirectory().toURI().toString(), "master", "sub1");
    CloneOperation op = new CloneOperation(repo);
    File dir = git.tempDirectory();
    Repository cloned = op.invoke(dir, null);
    assertNotNull(cloned);
    assertFalse(existing.getDirectory().equals(cloned.getDirectory()));
    assertFalse(new File(dir, Constants.DOT_GIT).exists());
    assertTrue(new File(dir, repo.getDirectory()).exists());
    assertTrue(new File(dir, repo.getDirectory() + File.separatorChar + Constants.DOT_GIT).exists());
    assertNotNull(CommitUtils.getCommit(cloned, commit));
}

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

License:Open Source License

public Repository invoke(File file, VirtualChannel channel) throws IOException {
    String directory = repo.getDirectory();
    File gitDir;/*w ww .j a  v  a2s.c  o m*/
    if (directory == null || directory.length() == 0 || ".".equals(directory))
        gitDir = file;
    else
        gitDir = new File(file, directory);
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    builder.setFS(FS.DETECTED);
    if (Constants.DOT_GIT.equals(gitDir.getName()))
        builder.setGitDir(gitDir);
    else
        builder.setWorkTree(gitDir);
    builder.setMustExist(true);
    try {
        return builder.build();
    } catch (RepositoryNotFoundException rnfe) {
        return null;
    }
}

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

License:Open Source License

/**
 * Initialize a new repo in a new directory
 * //from  w  w w . j  av  a  2s . c om
 * @return created .git folder
 */
public File initRepo() {
    File dir = tempDirectory();

    Git.init().setDirectory(dir).setBare(false).call();
    File repo = new File(dir, Constants.DOT_GIT);
    assertTrue(repo.exists());
    return repo;
}