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.jenkinsci.git.InitOperation.java

License:Open Source License

public Repository invoke(File file, VirtualChannel channel) throws IOException {
    String directory = repo.getDirectory();
    File gitDir;//from  w  w w  . j  a  va 2  s.  c  om
    if (directory == null || directory.length() == 0 || ".".equals(directory))
        gitDir = file;
    else
        gitDir = new File(file, directory);
    if (Constants.DOT_GIT.equals(gitDir.getName()))
        gitDir = new File(gitDir, Constants.DOT_GIT);
    InitCommand init = Git.init();
    init.setBare(false);
    init.setDirectory(gitDir);
    return init.call().getRepository();
}

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

License:Open Source License

/**
 * Testing initially cloning a repository and then fetching a new commit and
 * then another new commit//from w  w w .j ava  2 s.  co m
 *
 * @throws Exception
 */
@Test
public void checkoutThreeSequentialSingleCommits() throws Exception {
    File dir = git.tempDirectory();
    File gitDir = new File(dir, Constants.DOT_GIT);
    File log = File.createTempFile("log", ".txt");
    BuildRepository repo = new BuildRepository(git.repo().getDirectory().toURI().toString(),
            BuildRepository.BRANCH_DEFAULT, null);

    RevCommit commit1 = git.add("file.txt", "content");

    RepositoryCheckoutOperation op = new RepositoryCheckoutOperation(Collections.singletonList(repo),
            new FilePath(log));
    assertTrue(op.invoke(dir, null));

    CommitLogReader reader = new CommitLogReader();
    CommitLog cl = reader.parse(null, log);
    assertNotNull(cl);
    assertFalse(cl.isEmptySet());
    assertEquals(1, cl.toArray().length);
    assertEquals(commit1.name(), cl.iterator().next().getCommitId());
    assertTrue(log.delete());
    assertTrue(log.createNewFile());

    Repository gitRepo = new FileRepository(gitDir);
    assertFalse(git.repo().getDirectory().equals(gitRepo.getDirectory()));
    assertEquals(commit1, CommitUtils.getLatest(gitRepo));

    RevCommit commit2 = git.add("file.txt", "new content");
    assertTrue(op.invoke(dir, null));
    assertEquals(commit2, CommitUtils.getLatest(gitRepo));

    cl = reader.parse(null, log);
    assertNotNull(cl);
    assertFalse(cl.isEmptySet());
    assertEquals(1, cl.toArray().length);
    assertEquals(commit2.name(), cl.iterator().next().getCommitId());

    RevCommit commit3 = git.add("file.txt", "less content");
    assertTrue(op.invoke(dir, null));
    assertEquals(commit3, CommitUtils.getLatest(gitRepo));

    cl = reader.parse(null, log);
    assertNotNull(cl);
    assertFalse(cl.isEmptySet());
    assertEquals(1, cl.toArray().length);
    assertEquals(commit3.name(), cl.iterator().next().getCommitId());
}

From source file:org.kie.eclipse.navigator.view.server.KieRepositoryHandler.java

License:Open Source License

private void findGitDirsRecursive(File repoRoot, Set<File> gitDirs, IProgressMonitor monitor,
        boolean lookForNestedRepositories) {

    if (!repoRoot.exists() || !repoRoot.isDirectory()) {
        return;/*w  w w .  ja v  a 2s.  co  m*/
    }
    File[] children = repoRoot.listFiles();

    // simply ignore null
    if (children == null)
        return;

    for (File child : children) {
        if (monitor.isCanceled())
            return;
        if (!child.isDirectory())
            continue;

        if (FileKey.isGitRepository(child, FS.DETECTED)) {
            gitDirs.add(child);
        } else if (FileKey.isGitRepository(new File(child, Constants.DOT_GIT), FS.DETECTED)) {
            gitDirs.add(new File(child, Constants.DOT_GIT));
        } else if (lookForNestedRepositories) {
            monitor.subTask(child.getPath());
            findGitDirsRecursive(child, gitDirs, monitor, lookForNestedRepositories);
        }
    }
}

From source file:org.nbgit.Git.java

License:Open Source License

public Repository getRepository(File root) {
    Repository repo = repos.get(root);// w w  w  .  j  ava2 s. c  o m

    if (repo == null) {
        final File gitDir = new File(root, Constants.DOT_GIT);
        try {
            repo = new Repository(gitDir);
            repos.put(root, repo);
        } catch (IOException ex) {
        }
    }

    return repo;
}

From source file:org.openengsb.connector.git.internal.GitServiceImpl.java

License:Apache License

/**
 * Packs the files and directories of a passed {@link File} to a passed
 * {@link ArchiveOutputStream}./*  w  w w .j  a  va 2s . c  om*/
 *
 * @throws IOException
 */
private void packRepository(File source, ArchiveOutputStream aos) throws IOException {
    int bufferSize = 2048;
    byte[] readBuffer = new byte[bufferSize];
    int bytesIn = 0;
    File[] files = source.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return !pathname.getName().equals(Constants.DOT_GIT);
        }
    });
    for (File file : files) {
        if (file.isDirectory()) {
            ArchiveEntry ae = aos.createArchiveEntry(file, getRelativePath(file.getAbsolutePath()));
            aos.putArchiveEntry(ae);
            aos.closeArchiveEntry();
            packRepository(file, aos);
        } else {
            FileInputStream fis = new FileInputStream(file);
            ArchiveEntry ae = aos.createArchiveEntry(file, getRelativePath(file.getAbsolutePath()));
            aos.putArchiveEntry(ae);
            while ((bytesIn = fis.read(readBuffer)) != -1) {
                aos.write(readBuffer, 0, bytesIn);
            }
            aos.closeArchiveEntry();
            fis.close();
        }
    }
}

From source file:pl.project13.maven.git.GitDirLocator.java

License:Open Source License

@NotNull
private static File getProjectGitDir(@NotNull MavenProject mavenProject) {
    // FIXME Shouldn't this look at the dotGitDirectory property (if set) for the given project?
    return new File(mavenProject.getBasedir(), Constants.DOT_GIT);
}

From source file:services.player.ZoneManager.java

License:Open Source License

private void loadCommitHistory() {
    File repoDir = new File("./" + Constants.DOT_GIT);
    int commitCount = 3;
    int iterations = 0;

    try {/*w  w w  .  j  a  v a2s . c  om*/
        Git git = Git.open(repoDir);
        Repository repo = git.getRepository();

        try {
            commitHistory = "The " + commitCount + " most recent commits in branch '" + repo.getBranch()
                    + "':\n";

            for (RevCommit commit : git.log().setMaxCount(commitCount).call()) {
                commitHistory += commit.getName().substring(0, 7) + " " + commit.getShortMessage();

                if (commitCount > iterations++)
                    commitHistory += "\n";
            }
        } catch (GitAPIException e) {
            e.printStackTrace();
        }
    } catch (IOException e) {
        System.err.println("ZoneManager: Failed to open " + repoDir + " to read commit history");
        // An exception is thrown if bash isn't installed.
        // https://www.eclipse.org/forums/index.php/t/1031740/
    }
}