Example #1
0
        private void SetSubmoduleData(VsrModule currentModule, SubmoduleInfoResult result, string noBranchText, IVsrModule topProject)
        {
            var submodules = topProject.GetSubmodulesLocalPaths().OrderBy(submoduleName => submoduleName).ToArray();

            if (submodules.Any())
            {
                string localPath = result.Module.WorkingDir.Substring(topProject.WorkingDir.Length);
                localPath = Path.GetDirectoryName(localPath).ToPosixPath();

                foreach (var submodule in submodules)
                {
                    string path = topProject.GetSubmoduleFullPath(submodule);
                    string name = submodule + GetBranchNameSuffix(path, noBranchText);

                    bool bold = false;
                    if (submodule == localPath)
                    {
                        result.CurrentSubmoduleName = currentModule.GetCurrentSubmoduleLocalPath();
                        bold = true;
                    }

                    var smi = new SubmoduleInfo {
                        Text = name, Path = path, Bold = bold
                    };
                    result.SuperSubmodules.Add(smi);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Delete index.lock in the current working folder.
        /// </summary>
        /// <param name="includeSubmodules">
        ///     If <see langword="true"/> all submodules will be scanned for index.lock files and have them delete, if found.
        /// </param>
        /// <exception cref="FileDeleteException">Unable to delete specific index.lock.</exception>
        public void UnlockIndex(bool includeSubmodules = true)
        {
            var workingFolderIndexLock = Path.Combine(_gitDirectoryResolver.Resolve(_module.WorkingDir), IndexLock);

            if (!includeSubmodules)
            {
                DeleteIndexLock(workingFolderIndexLock);
                return;
            }

            // get the list of files to delete
            var submodules = _module.GetSubmodulesLocalPaths();
            var list       = submodules.Select(sm =>
            {
                var submodulePath      = _module.GetSubmoduleFullPath(sm);
                var submoduleIndexLock = Path.Combine(_gitDirectoryResolver.Resolve(submodulePath), IndexLock);
                return(submoduleIndexLock);
            }).Union(new[] { workingFolderIndexLock });

            foreach (var indexLock in list)
            {
                DeleteIndexLock(indexLock);
            }
        }
Example #3
0
        public void UnlockIndex_should_delete_submodule_locks_if_requested()
        {
            _file.Exists(_indexLockFile).Returns(true);

            var submoduleGitHubWorkingDir       = $@"{_workingDir}\Externals\Git.hub\";
            var submoduleNbugWorkingDir         = $@"{_workingDir}\Externals\NBug\";
            var submoduleGitHubWorkingDirGitDir = $@"{_gitWorkingDir}\modules\Externals\Git.hub\";
            var submoduleNBugWorkingDirGitDir   = $@"{_gitWorkingDir}\modules\Externals\NBug\";
            var submoduleGitHubIndexLock        = $@"{_gitWorkingDir}\modules\Externals\Git.hub\{IndexLock}";
            var submoduleNBugIndexLock          = $@"{_gitWorkingDir}\modules\Externals\NBug\{IndexLock}";

            _module.GetSubmodulesLocalPaths().Returns(new[] { "Externals/Git.hub", "Externals/NBug" });
            _module.GetSubmoduleFullPath(Arg.Any <string>())
            .Returns(submoduleGitHubWorkingDir, submoduleNbugWorkingDir);
            _gitDirectoryResolver.Resolve(submoduleGitHubWorkingDir).Returns(submoduleGitHubWorkingDirGitDir);
            _gitDirectoryResolver.Resolve(submoduleNbugWorkingDir).Returns(submoduleNBugWorkingDirGitDir);
            _file.Exists(submoduleGitHubIndexLock).Returns(true);
            _file.Exists(submoduleNBugIndexLock).Returns(false);

            _manager.UnlockIndex(true);

            _file.Received().Delete(submoduleGitHubIndexLock);
            _file.DidNotReceive().Delete(submoduleNBugIndexLock);
        }