Example usage for org.eclipse.jgit.submodule SubmoduleWalk getPath

List of usage examples for org.eclipse.jgit.submodule SubmoduleWalk getPath

Introduction

In this page you can find the example usage for org.eclipse.jgit.submodule SubmoduleWalk getPath.

Prototype

public String getPath() 

Source Link

Document

Get path of current submodule entry

Usage

From source file:com.bacoder.scmtools.git.internal.CloneAndProcessCommand.java

License:Apache License

@Override
protected void cloneSubmodules(Repository repository) throws IOException, GitAPIException {
    SubmoduleWalk generator;
    if (isInMemory()) {
        generator = new InMemorySubmoduleWalk(repository, submodulesConfig);
        try {/*from  www  .j a  v  a2s .co m*/
            DirCache index = repository.readDirCache();
            generator.setTree(new DirCacheIterator(index));
        } catch (IOException e) {
            generator.release();
            throw e;
        }
    } else {
        generator = SubmoduleWalk.forIndex(repository);
    }

    try {
        while (generator.next()) {
            if (generator.getConfigUrl() != null) {
                continue;
            }

            String path = generator.getPath();
            String url = generator.getRemoteUrl();

            CloneAndProcessCommand command = new CloneAndProcessCommand(path, config).setProcessor(processor);
            command.setURI(url).setCloneSubmodules(true);
            command.call();
        }
    } catch (ConfigInvalidException e) {
        throw new IOException("Config invalid", e);
    }
}

From source file:net.polydawn.mdm.MdmModuleRelease.java

License:Open Source License

public static MdmModuleRelease load(Repository parent, SubmoduleWalk generator, Config gitmodulesCfg)
        throws MdmRepositoryNonexistant, MdmRepositoryIOException, MdmModuleTypeException {
    try {//from  w  w w . j  a v  a 2  s.c  o  m
        return new MdmModuleRelease(generator.getRepository(), generator.getPath(), parent, gitmodulesCfg,
                generator.getObjectId());
    } catch (IOException e) {
        throw new MdmRepositoryIOException(false, generator.getPath(), e);
    }
}

From source file:net.polydawn.mdm.MdmModuleSet.java

License:Open Source License

public MdmModuleSet(Repository repo) throws IOException, ConfigInvalidException {
    gitmodulesCfg = new FileBasedConfig(new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS());
    gitmodulesCfg.load();//  w  ww  .j a  v a2 s .c o m

    /*
     * To maximize similarity with how the `git submodule` command behaves, we treat the SubmoduleWalk as canonical and the content of the .gitmodules file as tertiary.
     * However, that may change.  There's a lot about MdmModule that doesn't work without a .gitmodules entry anyway, so if it's faster to start from that list, we might as well.
     */

    SubmoduleWalk mw = new SubmoduleWalk(repo);
    mw.setModulesConfig(gitmodulesCfg);

    SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
    while (generator.next()) {
        try {
            // get the handle.  which we presume to be rather like the path, but git config always uses forward slashes.
            // (the MdmModule constructor will also enforce this, but here we have to walk config ourselves before we get that far.)
            String handle = (File.separatorChar != '/') ? generator.getPath().replace(File.separatorChar, '/')
                    : generator.getPath();

            // get submodule.[handle].mdm config value from gitmodules config file
            String type_configured_string = gitmodulesCfg.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
                    handle, MdmConfigConstants.Module.MODULE_TYPE.toString());
            MdmModuleType type_configured = MdmModuleType.fromString(type_configured_string);

            // if the submodule.[handle].mdm config value was unrecognized or missing, ignore; it's not ours.
            if (type_configured == null)
                continue;

            // load whichever type of mdm module it is
            switch (type_configured) {
            case DEPENDENCY:
                MdmModuleDependency modDep = MdmModuleDependency.load(repo, generator, gitmodulesCfg);
                dependencyModules.put(modDep.getHandle(), modDep);
                allModules.put(modDep.getHandle(), modDep);
                break;
            case RELEASES:
                MdmModuleRelease modRel = MdmModuleRelease.load(repo, generator, gitmodulesCfg);
                releasesModules.put(modRel.getHandle(), modRel);
                allModules.put(modRel.getHandle(), modRel);
                break;
            }
        } catch (MdmModuleTypeException e) {
            throw new MajorBug(e);
        } catch (MdmRepositoryNonexistant e) {
            throw e;
        } catch (MdmRepositoryIOException e) {
            throw e;
        }
    }
}

From source file:org.eclipse.egit.ui.internal.staging.StagingViewContentProvider.java

License:Open Source License

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    if (!(newInput instanceof StagingViewUpdate))
        return;/*from   ww w  . jav  a2  s . co m*/

    StagingViewUpdate update = (StagingViewUpdate) newInput;

    if (update.repository == null || update.indexDiff == null) {
        content = new StagingEntry[0];
        return;
    }

    Set<StagingEntry> nodes = new TreeSet<StagingEntry>(new Comparator<StagingEntry>() {
        public int compare(StagingEntry o1, StagingEntry o2) {
            return o1.getPath().compareTo(o2.getPath());
        }
    });

    if (update.changedResources != null && !update.changedResources.isEmpty()) {
        nodes.addAll(Arrays.asList(content));
        for (String res : update.changedResources)
            for (StagingEntry entry : content)
                if (entry.getPath().equals(res))
                    nodes.remove(entry);
    }

    final IndexDiffData indexDiff = update.indexDiff;
    final Repository repository = update.repository;
    if (isWorkspace) {
        for (String file : indexDiff.getMissing())
            nodes.add(new StagingEntry(repository, MISSING, file));
        for (String file : indexDiff.getModified())
            if (indexDiff.getChanged().contains(file))
                nodes.add(new StagingEntry(repository, PARTIALLY_MODIFIED, file));
            else
                nodes.add(new StagingEntry(repository, MODIFIED, file));
        for (String file : indexDiff.getUntracked())
            nodes.add(new StagingEntry(repository, UNTRACKED, file));
        for (String file : indexDiff.getConflicting())
            nodes.add(new StagingEntry(repository, CONFLICTING, file));
    } else {
        for (String file : indexDiff.getAdded())
            nodes.add(new StagingEntry(repository, ADDED, file));
        for (String file : indexDiff.getChanged())
            nodes.add(new StagingEntry(repository, CHANGED, file));
        for (String file : indexDiff.getRemoved())
            nodes.add(new StagingEntry(repository, REMOVED, file));
    }

    try {
        SubmoduleWalk walk = SubmoduleWalk.forIndex(repository);
        while (walk.next())
            for (StagingEntry entry : nodes)
                entry.setSubmodule(entry.getPath().equals(walk.getPath()));
    } catch (IOException e) {
        Activator.error(UIText.StagingViewContentProvider_SubmoduleError, e);
    }

    content = nodes.toArray(new StagingEntry[nodes.size()]);
}

From source file:org.gradle.vcs.fixtures.GitFileRepository.java

License:Apache License

/**
 * Updates any submodules in this repository to the latest in the submodule origin repository
 *//*from w ww.j av  a2s .  c  o m*/
public RevCommit updateSubmodulesToLatest() throws GitAPIException {
    List<String> submodulePaths = Lists.newArrayList();
    try {
        SubmoduleWalk walker = SubmoduleWalk.forIndex(git.getRepository());
        try {
            while (walker.next()) {
                Repository submodule = walker.getRepository();
                try {
                    submodulePaths.add(walker.getPath());
                    Git.wrap(submodule).pull().call();
                } finally {
                    submodule.close();
                }
            }
        } finally {
            walker.close();
        }
        return commit("update submodules", submodulePaths.toArray(new String[submodulePaths.size()]));
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}

From source file:org.gradle.vcs.git.internal.GitVersionControlSystem.java

License:Apache License

private static void updateSubModules(Git git) throws IOException, GitAPIException {
    SubmoduleWalk walker = SubmoduleWalk.forIndex(git.getRepository());
    try {//from  w  w w  .  j av a  2 s.  c o  m
        while (walker.next()) {
            Repository submodule = walker.getRepository();
            try {
                Git submoduleGit = Git.wrap(submodule);
                submoduleGit.fetch().call();
                git.submoduleUpdate().addPath(walker.getPath()).call();
                submoduleGit.reset().setMode(ResetCommand.ResetType.HARD).call();
                updateSubModules(submoduleGit);
            } finally {
                submodule.close();
            }
        }
    } finally {
        walker.close();
    }
}