コード例 #1
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);
        }
コード例 #2
0
        public void Setup()
        {
            _gitFile       = Path.Combine(_workingDir, ".git");
            _gitWorkingDir = _gitFile.EnsureTrailingPathSeparator();
            _indexLockFile = Path.Combine(_gitWorkingDir, IndexLock);

            _file       = Substitute.For <FileBase>();
            _directory  = Substitute.For <DirectoryBase>();
            _fileSystem = Substitute.For <IFileSystem>();
            _fileSystem.Directory.Returns(_directory);
            _fileSystem.File.Returns(_file);

            _module = Substitute.For <IGitModule>();
            _module.WorkingDir.Returns(_workingDir);

            _gitDirectoryResolver = Substitute.For <IGitDirectoryResolver>();
            _gitDirectoryResolver.Resolve(_workingDir).Returns(_gitWorkingDir);

            _manager = new IndexLockManager(_module, _gitDirectoryResolver, _fileSystem);
        }
コード例 #3
0
        /// <summary>
        /// Reads repository description's first line from ".git\description" file.
        /// </summary>
        /// <param name="workingDir">Path to repository.</param>
        /// <returns>If the repository has description, returns that description, else returns <c>null</c>.</returns>
        private string ReadRepositoryDescription(string workingDir)
        {
            var repositoryPath = _gitDirectoryResolver.Resolve(workingDir);
            var repositoryDescriptionFilePath = Path.Combine(repositoryPath, RepositoryDescriptionFileName);

            if (!File.Exists(repositoryDescriptionFilePath))
            {
                return(null);
            }

            try
            {
                var repositoryDescription = File.ReadLines(repositoryDescriptionFilePath).FirstOrDefault();
                return(string.Equals(repositoryDescription, DefaultDescription, StringComparison.CurrentCulture)
                    ? null
                    : repositoryDescription);
            }
            catch (IOException)
            {
                return(null);
            }
        }
コード例 #4
0
        /// <summary>
        /// Determines whether the given repository has index.lock file.
        /// </summary>
        /// <returns><see langword="true"/> is index is locked; otherwise <see langword="false"/>.</returns>
        public bool IsIndexLocked()
        {
            var indexLockFile = Path.Combine(_gitDirectoryResolver.Resolve(_module.WorkingDir), IndexLock);

            return(_fileSystem.File.Exists(indexLockFile));
        }