Package org.eclipse.jgit.submodule

Examples of org.eclipse.jgit.submodule.SubmoduleWalk


  public Map<String, SubmoduleStatus> call() throws JGitInternalException {
    checkCallable();

    try {
      SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
      if (!paths.isEmpty())
        generator.setFilter(PathFilterGroup.createFromStrings(paths));
      Map<String, SubmoduleStatus> statuses = new HashMap<String, SubmoduleStatus>();
      while (generator.next()) {
        SubmoduleStatus status = getStatus(generator);
        statuses.put(status.getPath(), status);
      }
      return statuses;
    } catch (IOException e) {
View Full Code Here


  public Collection<String> call() throws JGitInternalException {
    checkCallable();

    try {
      SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
      if (!paths.isEmpty())
        generator.setFilter(PathFilterGroup.createFromStrings(paths));
      List<String> updated = new ArrayList<String>();
      while (generator.next()) {
        // Skip submodules not registered in .gitmodules file
        if (generator.getModulesPath() == null)
          continue;
        // Skip submodules not registered in parent repository's config
        String url = generator.getConfigUrl();
        if (url == null)
          continue;

        Repository submoduleRepo = generator.getRepository();
        // Clone repository is not present
        if (submoduleRepo == null) {
          CloneCommand clone = Git.cloneRepository();
          configure(clone);
          clone.setURI(url);
          clone.setDirectory(generator.getDirectory());
          if (monitor != null)
            clone.setProgressMonitor(monitor);
          submoduleRepo = clone.call().getRepository();
        }

        RevWalk walk = new RevWalk(submoduleRepo);
        RevCommit commit = walk.parseCommit(generator.getObjectId());

        String update = generator.getConfigUpdate();
        if (ConfigConstants.CONFIG_KEY_MERGE.equals(update)) {
          MergeCommand merge = new MergeCommand(submoduleRepo);
          merge.include(commit);
          merge.call();
        } else if (ConfigConstants.CONFIG_KEY_REBASE.equals(update)) {
          RebaseCommand rebase = new RebaseCommand(submoduleRepo);
          rebase.setUpstream(commit);
          rebase.call();
        } else {
          // Checkout commit referenced in parent repository's index
          // as a detached HEAD
          DirCacheCheckout co = new DirCacheCheckout(submoduleRepo,
              submoduleRepo.lockDirCache(), commit.getTree());
          co.setFailOnConflict(true);
          co.checkout();
          RefUpdate refUpdate = submoduleRepo.updateRef(
              Constants.HEAD, true);
          refUpdate.setNewObjectId(commit);
          refUpdate.forceUpdate();
        }
        updated.add(generator.getPath());
      }
      return updated;
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } catch (ConfigInvalidException e) {
View Full Code Here

  public Collection<String> call() throws JGitInternalException {
    checkCallable();

    try {
      SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
      if (!paths.isEmpty())
        generator.setFilter(PathFilterGroup.createFromStrings(paths));
      StoredConfig config = repo.getConfig();
      List<String> initialized = new ArrayList<String>();
      while (generator.next()) {
        // Ignore entry if URL is already present in config file
        if (generator.getConfigUrl() != null)
          continue;

        String path = generator.getPath();
        // Copy 'url' and 'update' fields from .gitmodules to config
        // file
        String url = generator.getRemoteUrl();
        String update = generator.getModulesUpdate();
        if (url != null)
          config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
              path, ConfigConstants.CONFIG_KEY_URL, url);
        if (update != null)
          config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
View Full Code Here

  public Map<String, String> call() throws JGitInternalException {
    checkCallable();

    try {
      SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
      if (!paths.isEmpty())
        generator.setFilter(PathFilterGroup.createFromStrings(paths));
      Map<String, String> synced = new HashMap<String, String>();
      StoredConfig config = repo.getConfig();
      while (generator.next()) {
        String remoteUrl = generator.getRemoteUrl();
        if (remoteUrl == null)
          continue;

        String path = generator.getPath();
        config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
            path, ConfigConstants.CONFIG_KEY_URL, remoteUrl);
        synced.put(path, remoteUrl);

        Repository subRepo = generator.getRepository();
        if (subRepo == null)
          continue;

        StoredConfig subConfig = subRepo.getConfig();
        // Get name of remote associated with current branch and
View Full Code Here

      }
    }

    if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) {
      IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode;
      SubmoduleWalk smw = SubmoduleWalk.forIndex(repository);
      while (smw.next()) {
        try {
          if (localIgnoreSubmoduleMode == null)
            localIgnoreSubmoduleMode = smw.getModulesIgnore();
          if (IgnoreSubmoduleMode.ALL
              .equals(localIgnoreSubmoduleMode))
            continue;
        } catch (ConfigInvalidException e) {
          IOException e1 = new IOException(
              "Found invalid ignore param for submodule "
                  + smw.getPath());
          e1.initCause(e);
          throw e1;
        }
        Repository subRepo = smw.getRepository();
        if (subRepo != null) {
          ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$
          if (subHead != null && !subHead.equals(smw.getObjectId()))
            modified.add(smw.getPath());
          else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
            IndexDiff smid = submoduleIndexDiffs.get(smw.getPath());
            if (smid == null) {
              smid = new IndexDiff(subRepo, smw.getObjectId(),
                  wTreeIt.getWorkingTreeIterator(subRepo));
              submoduleIndexDiffs.put(smw.getPath(), smid);
            }
            if (smid.diff()) {
              if (ignoreSubmoduleMode == IgnoreSubmoduleMode.UNTRACKED
                  && smid.getAdded().isEmpty()
                  && smid.getChanged().isEmpty()
                  && smid.getConflicting().isEmpty()
                  && smid.getMissing().isEmpty()
                  && smid.getModified().isEmpty()
                  && smid.getRemoved().isEmpty()) {
                continue;
              }
              modified.add(smw.getPath());
            }
          }
        }
      }
View Full Code Here

    SubmoduleUpdateCommand update = new SubmoduleUpdateCommand(clonedRepo);
    configure(update);
    update.setProgressMonitor(monitor);
    if (!update.call().isEmpty()) {
      SubmoduleWalk walk = SubmoduleWalk.forIndex(clonedRepo);
      while (walk.next()) {
        Repository subRepo = walk.getRepository();
        if (subRepo != null) {
          try {
            cloneSubmodules(subRepo);
          } finally {
            subRepo.close();
View Full Code Here

  public Map<String, SubmoduleStatus> call() throws GitAPIException {
    checkCallable();

    try {
      SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
      if (!paths.isEmpty())
        generator.setFilter(PathFilterGroup.createFromStrings(paths));
      Map<String, SubmoduleStatus> statuses = new HashMap<String, SubmoduleStatus>();
      while (generator.next()) {
        SubmoduleStatus status = getStatus(generator);
        statuses.put(status.getPath(), status);
      }
      return statuses;
    } catch (IOException e) {
View Full Code Here

    assertNotNull(pathStatus);
    assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType());
    assertEquals(sub1Head, pathStatus.getHeadId());
    assertEquals(sub1Head, pathStatus.getIndexId());

    SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository());
    assertTrue(walk.next());
    Repository clonedSub1 = walk.getRepository();
    addRepoToClose(clonedSub1);
    assertNotNull(clonedSub1);
    status = new SubmoduleStatusCommand(clonedSub1);
    statuses = status.call();
    pathStatus = statuses.get(path);
    assertNotNull(pathStatus);
    assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType());
    assertEquals(sub2Head, pathStatus.getHeadId());
    assertEquals(sub2Head, pathStatus.getIndexId());
    assertFalse(walk.next());
  }
View Full Code Here

  public Collection<String> call() throws GitAPIException {
    checkCallable();

    try {
      SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
      if (!paths.isEmpty())
        generator.setFilter(PathFilterGroup.createFromStrings(paths));
      StoredConfig config = repo.getConfig();
      List<String> initialized = new ArrayList<String>();
      while (generator.next()) {
        // Ignore entry if URL is already present in config file
        if (generator.getConfigUrl() != null)
          continue;

        String path = generator.getPath();
        // Copy 'url' and 'update' fields from .gitmodules to config
        // file
        String url = generator.getRemoteUrl();
        String update = generator.getModulesUpdate();
        if (url != null)
          config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
              path, ConfigConstants.CONFIG_KEY_URL, url);
        if (update != null)
          config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
View Full Code Here

      WrongRepositoryStateException, NoMessageException, NoHeadException,
      RefNotFoundException, GitAPIException {
    checkCallable();

    try {
      SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
      if (!paths.isEmpty())
        generator.setFilter(PathFilterGroup.createFromStrings(paths));
      List<String> updated = new ArrayList<String>();
      while (generator.next()) {
        // Skip submodules not registered in .gitmodules file
        if (generator.getModulesPath() == null)
          continue;
        // Skip submodules not registered in parent repository's config
        String url = generator.getConfigUrl();
        if (url == null)
          continue;

        Repository submoduleRepo = generator.getRepository();
        // Clone repository is not present
        if (submoduleRepo == null) {
          CloneCommand clone = Git.cloneRepository();
          configure(clone);
          clone.setURI(url);
          clone.setDirectory(generator.getDirectory());
          if (monitor != null)
            clone.setProgressMonitor(monitor);
          submoduleRepo = clone.call().getRepository();
        }

        try {
          RevWalk walk = new RevWalk(submoduleRepo);
          RevCommit commit = walk
              .parseCommit(generator.getObjectId());

          String update = generator.getConfigUpdate();
          if (ConfigConstants.CONFIG_KEY_MERGE.equals(update)) {
            MergeCommand merge = new MergeCommand(submoduleRepo);
            merge.include(commit);
            merge.setStrategy(strategy);
            merge.call();
          } else if (ConfigConstants.CONFIG_KEY_REBASE.equals(update)) {
            RebaseCommand rebase = new RebaseCommand(submoduleRepo);
            rebase.setUpstream(commit);
            rebase.setStrategy(strategy);
            rebase.call();
          } else {
            // Checkout commit referenced in parent repository's
            // index as a detached HEAD
            DirCacheCheckout co = new DirCacheCheckout(
                submoduleRepo, submoduleRepo.lockDirCache(),
                commit.getTree());
            co.setFailOnConflict(true);
            co.checkout();
            RefUpdate refUpdate = submoduleRepo.updateRef(
                Constants.HEAD, true);
            refUpdate.setNewObjectId(commit);
            refUpdate.forceUpdate();
          }
        } finally {
          submoduleRepo.close();
        }
        updated.add(generator.getPath());
      }
      return updated;
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } catch (ConfigInvalidException e) {
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.submodule.SubmoduleWalk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.