Example usage for org.eclipse.jgit.lib Repository getDirectory

List of usage examples for org.eclipse.jgit.lib Repository getDirectory

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getDirectory.

Prototype


public File getDirectory() 

Source Link

Document

Get local metadata directory

Usage

From source file:org.kercoin.magrit.core.utils.GitUtils.java

License:Open Source License

public void addRemote(Repository toConfigure, String name, Repository remoteRepo) throws IOException {
    final String refSpec = String.format(REF_SPEC_PATTERN, name);
    File dest = remoteRepo.getDirectory();
    if (!remoteRepo.isBare()) {
        dest = dest.getParentFile();//from   w  ww.  java  2 s . c o  m
    }
    synchronized (toConfigure) {
        toConfigure.getConfig().setString("remote", name, "fetch", refSpec);
        toConfigure.getConfig().setString("remote", name, "url", dest.getAbsolutePath());
        // write down configuration in .git/config
        toConfigure.getConfig().save();
    }
}

From source file:org.kercoin.magrit.sshd.commands.MonitorCommand.java

License:Open Source License

@Override
public void buildEnded(Repository repo, String sha1, Status status) {
    synchronized (out) {
        printOut.println(//from w  w  w . j  a v a 2  s . c  o  m
                String.format("%s - Build ended %s on %s @ %s", now(), status, repo.getDirectory(), sha1));
        printOut.flush();
    }
}

From source file:org.kercoin.magrit.sshd.commands.ReceivePackCommand.java

License:Open Source License

Repository parse(String command) throws IOException {
    String parts[] = command.substring(17).split(" ");
    if (parts.length != 1) {
        throw new IllegalArgumentException(
                "Illegal git-receive-pack invokation ; the repository must be supplied");
    }/* w ww  .j a va  2s.co m*/

    String repoPath = parts[0].substring(1, parts[0].length() - 1);

    Repository repo = createRepository(repoPath);
    if (!repo.getDirectory().exists()) {
        repo.create(true);
    }
    return repo;
}

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

License:Open Source License

public Object load() {
    if (repository == null) {
        final File repoRoot = new File(PreferencesUtils.getRepoRoot(this));
        final Set<File> gitDirs = new HashSet<File>();
        final IRunnableWithProgress runnable = new IRunnableWithProgress() {

            @Override/*www. j a v  a 2  s.co  m*/
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Searching for Repositories", IProgressMonitor.UNKNOWN);
                try {
                    findGitDirsRecursive(repoRoot, gitDirs, monitor, false);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
            }
        };
        IProgressService ps = PlatformUI.getWorkbench().getProgressService();
        try {
            ps.busyCursorWhile(runnable);
        } catch (InvocationTargetException | InterruptedException e) {
            e.printStackTrace();
        }

        for (File dir : gitDirs) {
            if (getName().equals(dir.getParentFile().getName())) {
                try {
                    Repository repository = repositoryCache.lookupRepository(dir);
                    StoredConfig storedConfig = repository.getConfig();
                    Set<String> remotes = storedConfig.getSubsections("remote");
                    for (String remoteName : remotes) {
                        String url = storedConfig.getString("remote", remoteName, "url");
                        System.out.println(repository.getDirectory());
                        System.out.println(url);
                        try {
                            URI u = new URI(url);
                            int port = u.getPort();
                            String host = u.getHost();
                            String scheme = u.getScheme();
                            String path[] = u.getPath().split("/");
                            String repoName = path[path.length - 1];
                            if (name.equals(repoName) && host.equals(getServer().getHost())
                                    && port == getDelegate().getGitPort() && "ssh".equals(scheme)) {
                                this.repository = repository;
                                break;
                            }
                        } catch (URISyntaxException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

        if (repository != null)
            // TODO: why doesn't this work?
            repository.getListenerList().addListener(ConfigChangedListener.class, this);

    }
    return repository;
}

From source file:org.kie.eclipse.server.KieProjectHandler.java

License:Open Source License

@Override
public Object load() {
    if (project == null) {
        Repository repository = (Repository) parent.load();
        if (repository != null) {
            for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
                if (project.getName().equals(name)) {
                    File directory = project.getLocation().toFile();
                    final Set<File> gitDirs = new HashSet<File>();
                    GitUtils.findGitDirsRecursive(directory.getParentFile(), gitDirs, false);
                    for (File dir : gitDirs) {
                        if (repository.getDirectory().equals(dir)) {
                            this.project = project;
                            this.directory = directory;
                            break;
                        }//from  w  w w.  j a  v a 2 s.c  o  m
                    }
                }
                if (this.project != null)
                    break;
            }
        }
    }
    return project;
}

From source file:org.kuali.student.git.model.AbstractGitImporterMainTestCase.java

License:Educational Community License

protected void runImporter(Repository repository, long importRevision, String dumpFilePath, String repoURL,
        String repoUUID) throws IOException {

    SvnRevisionMapper revisionMapper = new SvnRevisionMapper(repository);
    //      //from  w  w  w  .java  2s . co m
    revisionMapper.initialize();

    Map<String, Ref> heads = repository.getRefDatabase().getRefs(Constants.R_HEADS);

    if (heads.size() > 0) {
        revisionMapper.createRevisionMap(importRevision - 1L, new ArrayList<Ref>(heads.values()));
    }

    revisionMapper.shutdown();

    if (enablePlugin)
        System.getProperties().setProperty("spring.profiles.active", "configured-plugin");

    GitImporterMain.main(new String[] { dumpFilePath, repository.getDirectory().getAbsolutePath(),
            "target/" + name + "-r" + importRevision + "-veto.log",
            "target/" + name + "-r" + importRevision + "-copyFrom-skipped.log",
            "target/" + name + "-r" + importRevision + "-blob.log", "0", repoURL, repoUUID });

}

From source file:org.kuali.student.git.model.SvnRevisionMapper.java

License:Educational Community License

/**
 * //from  w  ww.  j  a  v a2 s  .c o  m
 */
public SvnRevisionMapper(Repository repo) {

    treeProcessor = new GitTreeProcessor(repo);

    revisonMappings = new File(repo.getDirectory(), "jsvn");

    revisonMappings.mkdirs();

    revisionMapDataFile = new File(revisonMappings, REVISION_MAP_FILE_NAME);

    revisionMapIndexFile = new File(revisonMappings, REVISION_MAP_INDEX_FILE_NAME);

    revisionBranchMergeDataFile = new File(revisonMappings, REVISION_BRANCH_MERGE_FILE_NAME);

    revisionBranchMergeIndexFile = new File(revisonMappings, REVISION_BRANCH_MERGE_INDEX_FILE_NAME);

}

From source file:org.kuali.student.git.utils.ExternalGitUtils.java

License:Educational Community License

private static Process runGitCommand(Repository repo, boolean inGitMetaDirectory, List<String> commandArgs)
        throws IOException {

    File gitDirectory = null;/*w w w. j a va  2  s.c  o  m*/

    if (inGitMetaDirectory)
        gitDirectory = repo.getDirectory();
    else
        gitDirectory = repo.getWorkTree();

    // inherit the parent environment
    // locate in the working copy of the gir directory
    Process p = Runtime.getRuntime().exec(commandArgs.toArray(new String[] {}), null, gitDirectory);

    return p;
}

From source file:org.nbgit.junit.RepositoryTestCase.java

License:Open Source License

protected void copyRepositoryFiles(String name, Repository repo) throws IOException {
    copyDataFile(dataRoot, name + ".git", repo.getDirectory());
    copyDataFile(dataRoot, name + ".workdir", repo.getWorkDir());
    copyDataFile(dataDir, name + ".git", repo.getDirectory());
    copyDataFile(dataDir, name + ".workdir", repo.getWorkDir());
}

From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryIntegrationTests.java

License:Apache License

/**
 * Tests a special use case where the remote repository has been updated with a forced
 * push conflicting with the local repo of the Config Server. The Config Server has to
 * reset hard on the new reference because a simple pull operation could result in a
 * conflicting local repository./*  w  w w .  ja  v a 2s  .c  om*/
 */
@Test
public void pullDirtyRepo() throws Exception {
    ConfigServerTestUtils.prepareLocalRepo();
    String uri = ConfigServerTestUtils.copyLocalRepo("config-copy");

    // Create a remote bare repository.
    Repository remote = ConfigServerTestUtils.prepareBareRemote();

    Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile());
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", remote.getDirectory().getAbsolutePath());
    config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.save();

    // Pushes the raw branch to remote repository.
    git.push().call();

    String commitToRevertBeforePull = git.log().setMaxCount(1).call().iterator().next().getName();

    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
            .run("--spring.cloud.config.server.git.uri=" + uri);

    JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class);

    // Fetches the repository for the first time.
    SearchPathLocator.Locations locations = repository.getLocations("bar", "test", "raw");
    assertEquals(locations.getVersion(), commitToRevertBeforePull);

    // Resets to the original commit.
    git.reset().setMode(ResetType.HARD).setRef("master").call();

    // Generate a conflicting commit who will be forced on the origin.
    Path applicationFilePath = Paths.get(ResourceUtils.getFile(uri).getAbsoluteFile() + "/application.yml");

    Files.write(applicationFilePath, Arrays.asList("info:", "  foo: bar", "raw: false"), StandardCharsets.UTF_8,
            StandardOpenOption.TRUNCATE_EXISTING);
    git.add().addFilepattern(".").call();
    git.commit().setMessage("Conflicting commit.").call();
    git.push().setForce(true).call();
    String conflictingCommit = git.log().setMaxCount(1).call().iterator().next().getName();

    // Reset to the raw branch.
    git.reset().setMode(ResetType.HARD).setRef(commitToRevertBeforePull).call();

    // Triggers the repository refresh.
    locations = repository.getLocations("bar", "test", "raw");
    assertEquals(locations.getVersion(), conflictingCommit);

    assertTrue("Local repository is not cleaned after retrieving resources.", git.status().call().isClean());
}