/// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
 public override IDictionary <string, SubmoduleStatus> Call()
 {
     CheckCallable();
     try
     {
         SubmoduleWalk generator = SubmoduleWalk.ForIndex(repo);
         if (!paths.IsEmpty())
         {
             generator.SetFilter(PathFilterGroup.CreateFromStrings(paths));
         }
         IDictionary <string, SubmoduleStatus> statuses = new Dictionary <string, SubmoduleStatus
                                                                          >();
         while (generator.Next())
         {
             SubmoduleStatus status = GetStatus(generator);
             statuses.Put(status.GetPath(), status);
         }
         return(statuses);
     }
     catch (IOException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
     catch (ConfigInvalidException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
 }
Esempio n. 2
0
 /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
 public override ICollection <string> Call()
 {
     CheckCallable();
     try
     {
         SubmoduleWalk generator = SubmoduleWalk.ForIndex(repo);
         if (!paths.IsEmpty())
         {
             generator.SetFilter(PathFilterGroup.CreateFromStrings(paths));
         }
         StoredConfig   config      = repo.GetConfig();
         IList <string> initialized = new AList <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, path, ConfigConstants.
                                  CONFIG_KEY_UPDATE, update);
             }
             if (url != null || update != null)
             {
                 initialized.AddItem(path);
             }
         }
         // Save repository config if any values were updated
         if (!initialized.IsEmpty())
         {
             config.Save();
         }
         return(initialized);
     }
     catch (IOException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
     catch (ConfigInvalidException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
 }
Esempio n. 3
0
 /// <summary>Execute the SubmoduleUpdateCommand command.</summary>
 /// <remarks>Execute the SubmoduleUpdateCommand command.</remarks>
 /// <returns>a collection of updated submodule paths</returns>
 /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException">NGit.Api.Errors.ConcurrentRefUpdateException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.CheckoutConflictException">NGit.Api.Errors.CheckoutConflictException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.InvalidMergeHeadsException">NGit.Api.Errors.InvalidMergeHeadsException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.InvalidConfigurationException">NGit.Api.Errors.InvalidConfigurationException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.NoHeadException">NGit.Api.Errors.NoHeadException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.NoMessageException">NGit.Api.Errors.NoMessageException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.RefNotFoundException">NGit.Api.Errors.RefNotFoundException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.WrongRepositoryStateException">NGit.Api.Errors.WrongRepositoryStateException
 ///     </exception>
 /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException
 ///     </exception>
 public override ICollection <string> Call()
 {
     CheckCallable();
     try
     {
         SubmoduleWalk generator = SubmoduleWalk.ForIndex(repo);
         if (!paths.IsEmpty())
         {
             generator.SetFilter(PathFilterGroup.CreateFromStrings(paths));
         }
         IList <string> updated = new AList <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.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.Tree);
                         co.SetFailOnConflict(true);
                         co.Checkout();
                         RefUpdate refUpdate = submoduleRepo.UpdateRef(Constants.HEAD, true);
                         refUpdate.SetNewObjectId(commit);
                         refUpdate.ForceUpdate();
                     }
                 }
             }
             finally
             {
                 submoduleRepo.Close();
             }
             updated.AddItem(generator.GetPath());
         }
         return(updated);
     }
     catch (IOException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
     catch (ConfigInvalidException e)
     {
         throw new InvalidConfigurationException(e.Message, e);
     }
 }
 /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
 public override IDictionary <string, string> Call()
 {
     CheckCallable();
     try
     {
         SubmoduleWalk generator = SubmoduleWalk.ForIndex(repo);
         if (!paths.IsEmpty())
         {
             generator.SetFilter(PathFilterGroup.CreateFromStrings(paths));
         }
         IDictionary <string, string> synced = new Dictionary <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;
             string       branch;
             try
             {
                 subConfig = subRepo.GetConfig();
                 // Get name of remote associated with current branch and
                 // fall back to default remote name as last resort
                 branch = GetHeadBranch(subRepo);
                 string remote = null;
                 if (branch != null)
                 {
                     remote = subConfig.GetString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants
                                                  .CONFIG_KEY_REMOTE);
                 }
                 if (remote == null)
                 {
                     remote = Constants.DEFAULT_REMOTE_NAME;
                 }
                 subConfig.SetString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants
                                     .CONFIG_KEY_URL, remoteUrl);
                 subConfig.Save();
             }
             finally
             {
                 subRepo.Close();
             }
         }
         if (!synced.IsEmpty())
         {
             config.Save();
         }
         return(synced);
     }
     catch (IOException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
     catch (ConfigInvalidException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
 }