Exemple #1
0
        public void LongUnknownFileIsfilteredOut()
        {
            using (var bob = new RepositorySetup("bob"))
            {
                const string fileName = "test.chorusTest";
                bob.ChangeFile(fileName, _longData);
                var fullPathname = Path.Combine(bob.ProjectFolderConfig.FolderPath, fileName);
                var pathToRepo   = bob.Repository.PathToRepo + Path.DirectorySeparatorChar;

                var config = bob.ProjectFolderConfig;
                config.ExcludePatterns.Clear();
                config.IncludePatterns.Clear();
                config.IncludePatterns.Add("**.chorusTest");

                var result = LargeFileFilter.FilterFiles(
                    bob.Repository,
                    config,
                    _handlersColl);
                Assert.IsFalse(string.IsNullOrEmpty(result));
                var shortpath = fullPathname.Replace(pathToRepo, "");
                Assert.IsTrue(config.ExcludePatterns.Contains(shortpath));
                Assert.IsFalse(config.IncludePatterns.Contains(shortpath));
            }
        }
Exemple #2
0
        public void NormallyExcludedNestedLargeFileIsNotAddedByLargeFileFilter()
        {
            using (var bob = new RepositorySetup("bob"))
            {
                var megabyteLongData = "long" + Environment.NewLine;
                while (megabyteLongData.Length < LargeFileFilter.Megabyte)
                {
                    megabyteLongData += megabyteLongData;
                }

                const string largeDictionaryFilename = "whopper.dic";
                var          nestedFolder            = Path.Combine(bob.Repository.PathToRepo, "nestedFolder");
                Directory.CreateDirectory(nestedFolder);
                var largeDictionaryPathname = Path.Combine("nestedFolder", largeDictionaryFilename);

                bob.ChangeFile(largeDictionaryPathname, megabyteLongData);
                var fullDictionaryPathname = Path.Combine(bob.ProjectFolderConfig.FolderPath, largeDictionaryPathname);
                var pathToRepo             = bob.Repository.PathToRepo + Path.DirectorySeparatorChar;
                bob.Repository.TestOnlyAddSansCommit(fullDictionaryPathname);

                var config = bob.ProjectFolderConfig;
                config.ExcludePatterns.Clear();
                config.ExcludePatterns.Add(Path.Combine("nestedFolder", "whopper.dic"));
                config.IncludePatterns.Clear();
                config.IncludePatterns.Add("**.*");

                var result = LargeFileFilter.FilterFiles(
                    bob.Repository,
                    config,
                    ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers());
                Assert.IsTrue(string.IsNullOrEmpty(result));
                var shortpath = fullDictionaryPathname.Replace(pathToRepo, "");
                Assert.IsTrue(config.ExcludePatterns.Contains(shortpath));
                Assert.IsFalse(config.IncludePatterns.Contains(shortpath));
            }
        }
Exemple #3
0
        public void FileWithSpecialCharacterIsAllowed()
        {
            using (var bob = new RepositorySetup("bob"))
            {
                const string fileName = "ŭburux.wav";
                bob.ChangeFile(fileName, _goodData);
                var fullPathname = Path.Combine(bob.ProjectFolderConfig.FolderPath, fileName);
                var pathToRepo   = bob.Repository.PathToRepo + Path.DirectorySeparatorChar;
                bob.Repository.TestOnlyAddSansCommit(fullPathname);
                var config = bob.ProjectFolderConfig;
                config.ExcludePatterns.Clear();
                config.IncludePatterns.Clear();
                config.IncludePatterns.Add("**.wav");

                var result = LargeFileFilter.FilterFiles(
                    bob.Repository,
                    config,
                    _handlersColl);
                Assert.IsTrue(string.IsNullOrEmpty(result));
                var shortpath = fullPathname.Replace(pathToRepo, "");
                Assert.IsFalse(config.ExcludePatterns.Contains(shortpath));
                Assert.IsFalse(config.IncludePatterns.Contains(shortpath));
            }
        }
        public void GetFilteredStatusForFilesHasExpectedResults()
        {
            using (var repo = new RepositorySetup("BigFiles", true))
            {
                // 'clean' - C
                repo.AddAndCheckinFile("control.txt", "original");
                repo.AddAndCheckinFile("modified.txt", "original");
                repo.AddAndCheckinFile("removed.txt", "removed properly");
                repo.AddAndCheckinFile("goner.txt", "short lived");
                File.WriteAllText(Path.Combine(repo.ProjectFolder.Path, "added.txt"), "added file");

                // 'modified' - M
                repo.ChangeFile("modified.txt", "updated");

                // 'added' - A
                repo.Repository.Execute(10, "add", "added.txt");

                // 'removed' - R
                repo.Repository.Execute(10, "rm", "removed.txt");

                // 'missing' - !
                File.Delete(Path.Combine(repo.ProjectFolder.Path, "goner.txt"));

                // 'unknown' - ?
                File.WriteAllText(Path.Combine(repo.ProjectFolder.Path, "unknown.txt"), "new data");

                // excluded
                File.WriteAllText(Path.Combine(repo.ProjectFolder.Path, "unknown.jpg"), "some binary data");

                repo.ProjectFolderConfig.ExcludePatterns.Add("*.jpg");
                repo.ProjectFolderConfig.IncludePatterns.Add("*.txt");

                var results = LargeFileFilter.GetStatusOfFilesOfInterest(repo.Repository, repo.ProjectFolderConfig);
                Assert.AreEqual(3, results.Keys.Count);
                Assert.IsTrue(results.ContainsKey("M"));                 // tracked and modifed
                Assert.IsTrue(results.ContainsKey("A"));                 // Added with hg add
                Assert.IsTrue(results.ContainsKey("?"));                 // untracked

                foreach (var resultKvp in results)
                {
                    var resultValue = resultKvp.Value;
                    Assert.AreEqual(1, resultValue.Keys.Count);
                    Assert.IsTrue(resultValue.ContainsKey("txt"));
                    Assert.AreEqual(1, resultValue.Values.Count);
                    switch (resultKvp.Key)
                    {
                    case "M":
                        Assert.AreEqual("modified.txt", resultValue["txt"][0]);
                        break;

                    case "A":
                        Assert.AreEqual("added.txt", resultValue["txt"][0]);
                        break;

                    case "?":
                        Assert.AreEqual("unknown.txt", resultValue["txt"][0]);
                        break;
                    }
                }
            }
        }