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.eclipse.mylyn.reviews.r4e.ui.tests.utils.TestUtils.java

License:Open Source License

private static void connectProjectWithRepo(IProject aProject, Repository aRepository)
        throws CoreException, IOException {
    ConnectProviderOperation op = new ConnectProviderOperation(aProject, aRepository.getDirectory());
    op.execute(null);//from  w ww .j a v  a  2  s . c  o m
}

From source file:org.eclipse.orion.server.git.servlets.GitSubmoduleHandlerV1.java

License:Open Source License

public static void removeSubmodule(Repository db, Repository parentRepo, String pathToSubmodule)
        throws Exception {
    pathToSubmodule = pathToSubmodule.replace("\\", "/");
    StoredConfig gitSubmodulesConfig = getGitSubmodulesConfig(parentRepo);
    gitSubmodulesConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule);
    gitSubmodulesConfig.save();// ww w  .jav  a 2 s .c o  m
    StoredConfig repositoryConfig = parentRepo.getConfig();
    repositoryConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule);
    repositoryConfig.save();
    Git git = Git.wrap(parentRepo);
    git.add().addFilepattern(DOT_GIT_MODULES).call();
    RmCommand rm = git.rm().addFilepattern(pathToSubmodule);
    if (gitSubmodulesConfig.getSections().size() == 0) {
        rm.addFilepattern(DOT_GIT_MODULES);
    }
    rm.call();
    FileUtils.delete(db.getWorkTree(), FileUtils.RECURSIVE);
    FileUtils.delete(db.getDirectory(), FileUtils.RECURSIVE);
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java

License:Open Source License

@Test
public void testDeleteInWorkspace() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    JSONObject clone = clone(clonePath);
    String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
    String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

    Repository repository = getRepositoryForContentLocation(contentLocation);
    assertNotNull(repository);//from   w  ww . j  a  v  a2 s. c o m

    // delete folder with cloned repository in it
    WebRequest request = getDeleteFilesRequest(contentLocation);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // the clone is gone
    request = getGetRequest(cloneLocation);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());

    assertFalse(repository.getDirectory().exists());
}

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitRepo.java

License:Open Source License

/**
 * Upload the file filter from the given JGit repository
 *
 * @param localJGitRepo/*from ww w.ja  v a2  s  .  co m*/
 * @param monitor
 *
 * @throws MissingConnectionException
 *          on missing connection
 * @throws RemoteSyncException
 *          on problems executing remote commands
 */
public void uploadFilter(JGitRepo localJGitRepo, IProgressMonitor monitor)
        throws MissingConnectionException, RemoteSyncException {
    final RecursiveSubMonitor subMon = RecursiveSubMonitor.convert(monitor, 10);
    IRemoteConnection conn = remoteLoc.getConnection();
    Repository repository = localJGitRepo.getRepository();

    try {
        //copy info/exclude to remote
        File exclude = repository.getFS().resolve(repository.getDirectory(), Constants.INFO_EXCLUDE);
        IFileStore local = EFS.getLocalFileSystem().getStore(new Path(exclude.getAbsolutePath()));
        String remoteExclude = remoteLoc.getDirectory() + "/" + GitSyncService.gitDir + "/" //$NON-NLS-1$//$NON-NLS-2$
                + Constants.INFO_EXCLUDE;
        IFileStore remote = conn.getFileManager().getResource(remoteExclude);
        subMon.subTask(Messages.GitRepo_6);
        local.copy(remote, EFS.OVERWRITE, subMon.newChild(3));

        //remove ignored files from index
        if (remoteGitVersion >= 1080102) {
            final String command = gitCommand() + " ls-files -X " + GitSyncService.gitDir + "/" //$NON-NLS-1$//$NON-NLS-2$
                    + Constants.INFO_EXCLUDE + " -i | " + //$NON-NLS-1$
                    gitCommand() + " update-index --force-remove --stdin ; " + //$NON-NLS-1$
                    gitCommand() + " commit --allow-empty -m \"" + GitSyncService.commitMessage + "\""; //$NON-NLS-1$ //$NON-NLS-2$
            subMon.subTask(Messages.GitRepo_7);
            CommandResults commandResults = this.executeRemoteCommand(command, subMon.newChild(7));
            if (commandResults.getExitCode() != 0) {
                throw new RemoteSyncException(Messages.GitRepo_8 + commandResults.getStderr());
            }
        } else {
            final String command = gitCommand() + " rev-parse HEAD"; //$NON-NLS-1$
            subMon.subTask(Messages.GitRepo_9);
            CommandResults commandResults = this.executeRemoteCommand(command, subMon.newChild(2));
            ObjectId objectId = null;
            if (commandResults.getExitCode() == 0)
                objectId = repository.resolve(commandResults.getStdout().trim());
            RevTree ref = null;
            try {
                if (objectId != null)
                    ref = new RevWalk(repository).parseTree(objectId);
            } catch (Exception e) {
                //ignore. Can happen if the local repo doesn't yet have the remote commit
            }
            if (ref != null) {
                Set<String> filesToRemove = localJGitRepo.getFilter().getIgnoredFiles(ref);
                subMon.subTask(Messages.GitRepo_7);
                deleteRemoteFiles(filesToRemove, subMon.newChild(8));
            }
        }
    } catch (RemoteConnectionException e) {
        throw new RemoteSyncException(e);
    } catch (CoreException e) {
        throw new RemoteSyncException(e);
    } catch (IOException e) {
        throw new RemoteSyncException(e);
    } catch (InterruptedException e) {
        throw new RemoteSyncException(e);
    } catch (RemoteExecutionException e) {
        throw new RemoteSyncException(e);
    }
}

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java

License:Open Source License

@Override
public void saveFilter() throws IOException {
    Repository repo = jgitRepo.getRepository();
    File exclude = repo.getFS().resolve(repo.getDirectory(), Constants.INFO_EXCLUDE);
    exclude.getParentFile().mkdirs();/*from w  w w .j  a  va2s  .c o m*/
    FileOutputStream file = new FileOutputStream(exclude);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(file, Constants.CHARSET));
    try {
        for (AbstractIgnoreRule rule : rules) {
            out.write(rule.toString());
            out.newLine();
        }
    } finally {
        out.close();
    }
    final RmCommand rmCommand = new RmCommand(repo);
    rmCommand.setCached(true);
    for (String fileName : getIgnoredFiles(null)) {
        rmCommand.addFilepattern(fileName);
    }
    try {
        rmCommand.call();
    } catch (NoFilepatternException e) {
        new IOException(e); // TODO: a bit ugly to wrap it into IOExcpetion
    } catch (GitAPIException e) {
        new IOException(e);
    }
}

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java

License:Open Source License

/**
 * Load filtering rules from the file system
 * @throws IOException/*w  w  w.  j a v a 2s.com*/
 *          on problems reading from the file system
 */
public void loadFilter() throws IOException {
    Repository repo = jgitRepo.getRepository();
    File exclude = repo.getFS().resolve(repo.getDirectory(), Constants.INFO_EXCLUDE);
    if (exclude.exists()) {
        FileInputStream in = new FileInputStream(exclude);
        try {
            IgnoreNode node = new IgnoreNode();
            node.parse(in);
            for (org.eclipse.jgit.ignore.IgnoreRule rule : node.getRules()) {
                rules.add(new GitIgnoreRule(rule));
            }
        } finally {
            in.close();
        }
    } else {
        initialize(SyncManager.getDefaultFileFilter());
    }
}

From source file:org.flowerplatform.web.git.explorer.RepositoryNodeDataProvider.java

License:Open Source License

@Override
public boolean populateTreeNode(Object source, TreeNode destination, GenericTreeContext context) {
    Repository repository = (Repository) source;

    destination.setLabel(repository.getDirectory().getParentFile().getParentFile().getName());
    destination.setIcon(GitPlugin.getInstance().getResourceUrl("images/full/obj16/repository_rep.gif"));
    return true;//w  ww.  j a v a  2 s .  c om
}

From source file:org.flowerplatform.web.git.explorer.RepositoryNodeDataProvider.java

License:Open Source License

@Override
public PathFragment getPathFragmentForNode(Object node, String nodeType, GenericTreeContext context) {
    Repository repository = (Repository) node;
    File mainRepoFile = repository.getDirectory().getParentFile();
    return new PathFragment(mainRepoFile.getParentFile().getName(), nodeType);
}

From source file:org.flowerplatform.web.git.explorer.RepositoryNodeDataProvider.java

License:Open Source License

@Override
public String getLabelForLog(Object node, String nodeType) {
    Repository repository = (Repository) node;
    return repository.getDirectory().getParentFile().getParentFile().getName();
}

From source file:org.flowerplatform.web.git.explorer.WorkingDirectory_VirtualItemChildrenProvider.java

License:Open Source License

@Override
public Collection<Pair<Object, String>> getChildrenForNode(Object node, TreeNode treeNode,
        GenericTreeContext context) {/*w  ww .ja v  a  2  s  . c  om*/
    @SuppressWarnings("unchecked")
    Repository repository = ((Pair<Repository, String>) node).a;
    File[] children = repository.getDirectory().getParentFile().getParentFile().listFiles();

    Collection<Pair<Object, String>> result = new ArrayList<Pair<Object, String>>(children.length);
    for (File child : children) {
        Repository repo = GitPlugin.getInstance().getUtils().getRepository(child);

        if (repo != null) {
            Pair<Object, String> pair = new Pair<Object, String>(
                    new Pair<File, String>(child, GitNodeType.NODE_TYPE_WDIR), GitNodeType.NODE_TYPE_WDIR);
            result.add(pair);
        }
    }
    return result;
}