Esempio n. 1
0
        public void FileViewer_ShowSyntaxHighlightingInDiff_enabled_use_highlighting()
        {
            // a sample c sharp file diff
            const string sampleCsharpPatch =
                @"diff --git a/GitUI/Editor/FileViewerInternal.cs b/GitUI/Editor/FileViewerInternal.cs
index 62a5c2f08..2bc482714 100644
--- a/GitUI/Editor/FileViewerInternal.cs
+++ b/GitUI/Editor/FileViewerInternal.cs
@@ -229 +229 @@ public void SetText(string text, Action openWithDifftool, bool isDiff = false)
-            int scrollPos = ScrollPos;
+            int scrollPos = VScrollPosition;";

            using var testHelper = new GitModuleTestHelper();
            var uiCommands = new GitUICommands(testHelper.Module);

            _uiCommandsSource.UICommands.Returns(x => uiCommands);
            _fileViewer.UICommandsSource = _uiCommandsSource;

            FileViewer.TestAccessor testAccessor = _fileViewer.GetTestAccessor();
            testAccessor.ShowSyntaxHighlightingInDiff = true;

            // act
            testAccessor.ViewPatch("FileViewerInternal.cs", sampleCsharpPatch);

            // assert
            IHighlightingStrategy csharpHighlighting = HighlightingManager.Manager.FindHighlighterForFile("anycsharpfile.cs");

            csharpHighlighting.Should().NotBe(HighlightingManager.Manager.DefaultHighlighting);

            _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.Document
            .HighlightingStrategy.Should().Be(csharpHighlighting);
        }
        public void SetUp()
        {
            _repo1 = new GitModuleTestHelper("repo1");
            _repo2 = new GitModuleTestHelper("repo2");
            _repo3 = new GitModuleTestHelper("repo3");

            _repo2.AddSubmodule(_repo3, "repo3");
            _repo1.AddSubmodule(_repo2, "repo2");
            var submodules = _repo1.GetSubmodulesRecursive();

            _repo1Module = _repo1.Module;
            _repo2Module = submodules.ElementAt(0);
            _repo3Module = submodules.ElementAt(1);

            // Use the singleton provider, which is also used by the left panel, so we can synchronize on updates
            _provider = SubmoduleStatusProvider.Default;

            _commands = new GitUICommands(_repo1Module);

            var composition = TestComposition.Empty
                              .AddParts(typeof(MockWindowsJumpListManager))
                              .AddParts(typeof(MockRepositoryDescriptionProvider))
                              .AddParts(typeof(MockAppTitleGenerator));
            ExportProvider mefExportProvider = composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
Esempio n. 3
0
        public void FileViewer_given_non_text_use_default_highlighting()
        {
            // a sample c sharp file diff
            const string sampleBinaryPatch =
                @"diff --git a/binaryfile.bin b/binaryfile.bin
index b25b745..5194740 100644
Binary files a/binaryfile.bin and b/binaryfile.bin differ";

            using var testHelper = new GitModuleTestHelper();
            var uiCommands = new GitUICommands(testHelper.Module);

            _uiCommandsSource.UICommands.Returns(x => uiCommands);
            _fileViewer.UICommandsSource = _uiCommandsSource;

            FileViewer.TestAccessor testAccessor = _fileViewer.GetTestAccessor();

            // act
            testAccessor.ViewPatch("binaryfile.bin", sampleBinaryPatch, null);

            // assert
            testAccessor.FileViewerInternal.GetTestAccessor().TextEditor.Document.HighlightingStrategy.Should().Be(HighlightingManager.Manager.DefaultHighlighting);

            const string sampleRandomText =
                @"fldaksjflkdsjlfj";

            // act
            testAccessor.ViewPatch(null, sampleRandomText, null);

            // assert
            _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.Document.HighlightingStrategy.Should().Be(HighlightingManager.Manager.DefaultHighlighting);
        }
        public void DoAutoCRLF_should_not_unnecessarily_duplicate_line_ending(AutoCRLFType autoCRLFType, string file)
        {
            using (var testHelper = new GitModuleTestHelper())
            {
                testHelper.Module.LocalConfigFile.SetEnum("core.autocrlf", autoCRLFType);
                testHelper.Module.LocalConfigFile.Save();

                var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.{file}.bin");

                var uiCommands = new GitUICommands(testHelper.Module);
                _uiCommandsSource.UICommands.Returns(x => uiCommands);
                _fileViewer.UICommandsSource = _uiCommandsSource;

                var fvi = _fileViewer.GetTestAccessor().FileViewerInternal;
                fvi.SetText(content, null, false);
                var doc = fvi.GetTestAccessor().TextEditor.Document;
                var end = doc.OffsetToPosition(content.Length);
                fvi.GetTestAccessor().TextEditor.ActiveTextAreaControl.SelectionManager.SetSelection(new TextLocation(0, 0), end);

                // act - 'copy to selection' menu click will call through to DoAutoCRLF
                _fileViewer.GetTestAccessor().CopyToolStripMenuItem.PerformClick();

                // assert
                var text = Clipboard.GetText();
                using (ApprovalResults.ForScenario(file, autoCRLFType))
                {
                    Approvals.Verify(text);
                }
            }
        }
 public void Resolve_non_bare_repository_real_filsystem()
 {
     _resolver = new GitDirectoryResolver();
     using (var helper = new GitModuleTestHelper())
     {
         _resolver.Resolve(helper.Module.WorkingDir).Should().Be(helper.Module.WorkingDirGitDir);
     }
 }
        public void TearDown()
        {
            _userRoaming.SettingsCache.Dispose();
            _repoDistributed.SettingsCache.Dispose();
            _repoLocal.SettingsCache.Dispose();

            _testHelper.Dispose();
            _testHelper = null;
        }
Esempio n. 7
0
        public void Resolve_submodule_real_filsystem_Mono()
        {
            using (var helper = new GitModuleTestHelper())
            {
                var submodulePath = Path.Combine(helper.Module.WorkingDir, "External", "Git.hub");
                helper.CreateFile(submodulePath, ".git", "\r \r\ngitdir: ../../.git/modules/Externals/Git.hub\r\ntext");
                _resolver = new GitDirectoryResolver();

                _resolver.Resolve(submodulePath).Should().Be($@"{helper.Module.WorkingDirGitDir}modules/Externals/Git.hub/");
            }
        }
Esempio n. 8
0
        public void TryGetExactPathName_should_check_if_path_matches_case(string relativePath, bool isResolved, bool doesMatch)
        {
            using var repo = new GitModuleTestHelper();

            // Create a file
            var notUsed = repo.CreateFile(Path.Combine(repo.TemporaryPath, "Folder1"), "file1.txt", "bla");

            var expected = Path.Combine(repo.TemporaryPath, relativePath);

            Assert.AreEqual(isResolved, _controller.TryGetExactPath(expected, out string exactPath));
            Assert.AreEqual(doesMatch, exactPath == expected);
        }
            public void ToggleRemoteState_should_not_fail_if_deactivate_repeatedly()
            {
                using var helper = new GitModuleTestHelper();
                var manager = new ConfigFileRemoteSettingsManager(() => helper.Module);

                const string remoteName = "active";

                helper.Module.AddRemote(remoteName, "http://localhost/remote/repo.git");
                manager.ToggleRemoteState(remoteName, true);

                helper.Module.AddRemote(remoteName, "http://localhost/remote/repo.git");
                manager.ToggleRemoteState(remoteName, true);
            }
Esempio n. 10
0
        public void Can_load_settings(string fileName, int expected)
        {
            var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.{fileName}.settings.xml");

            using var testHelper = new GitModuleTestHelper();
            var settingsFile = testHelper.CreateRepoFile(".git", "GitExtensions.settings", content);

            using var settingsCache = new GitExtSettingsCache(settingsFile);
            var settings = new RepoDistSettings(null, settingsCache, SettingLevel.Unknown);

            var definitions = _externalLinksStorage.Load(settings);

            definitions.Count.Should().Be(expected);
        }
        public void SetUp()
        {
            _repo1 = new GitModuleTestHelper("repo1");
            _repo2 = new GitModuleTestHelper("repo2");
            _repo3 = new GitModuleTestHelper("repo3");

            _repo2.AddSubmodule(_repo3, "repo3");
            _repo1.AddSubmodule(_repo2, "repo2");
            var submodules = _repo1.GetSubmodulesRecursive();

            _repo1Module = _repo1.Module;
            _repo2Module = submodules.ElementAt(0);
            _repo3Module = submodules.ElementAt(1);

            _provider = new SubmoduleStatusProvider();
        }
Esempio n. 12
0
        public void Setup()
        {
            _testHelper = new GitModuleTestHelper();

            var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level1_GitExtensions.settings.xml");

            _level1 = _testHelper.CreateRepoFile(".git", "GitExtensions.settings", content);
            content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level2_GitExtensions.settings.xml");
            _level2 = _testHelper.CreateFile(_testHelper.TemporaryPath + "/RoamingProfile", "GitExtensions.settings", content);
            content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level3_GitExtensions.settings.xml");
            _level3 = _testHelper.CreateRepoFile("GitExtensions.settings", content);

            _userRoaming     = new RepoDistSettings(null, new GitExtSettingsCache(_level3));
            _repoDistributed = new RepoDistSettings(_userRoaming, new GitExtSettingsCache(_level2));
            _repoLocal       = new RepoDistSettings(_repoDistributed, new GitExtSettingsCache(_level1));
        }
        public ReferenceRepository(GitModuleTestHelper moduleTestHelper)
        {
            _moduleTestHelper = moduleTestHelper;

            using (var repository = new LibGit2Sharp.Repository(_moduleTestHelper.Module.WorkingDir))
            {
                _moduleTestHelper.CreateRepoFile("A.txt", "A");
                repository.Index.Add("A.txt");

                var message   = "A commit message";
                var author    = new LibGit2Sharp.Signature("GitUITests", "*****@*****.**", DateTimeOffset.Now);
                var committer = author;
                var options   = new LibGit2Sharp.CommitOptions();
                var commit    = repository.Commit(message, author, committer, options);
                CommitHash = commit.Id.Sha;
            }
        }
        public void Setup()
        {
            _testHelper = new GitModuleTestHelper();

            var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level3_roaming_GitExtensions.settings.xml");

            _userRoamingConfigFilePath = _testHelper.CreateFile(_testHelper.TemporaryPath + "/RoamingProfile", "GitExtensions.settings", content);
            content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level2_repodist_GitExtensions.settings.xml");
            _repoDistributedConfigFilePath = _testHelper.CreateRepoFile("GitExtensions.settings", content);
            content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level1_repogit_GitExtensions.settings.xml");
            _repoLocalConfigFilePath = _testHelper.CreateRepoFile(".git", "GitExtensions.settings", content);

            _userRoaming     = new RepoDistSettings(null, new GitExtSettingsCache(_userRoamingConfigFilePath), SettingLevel.Global);
            _repoDistributed = new RepoDistSettings(_userRoaming, new GitExtSettingsCache(_repoDistributedConfigFilePath), SettingLevel.Distributed);
            _repoLocal       = new RepoDistSettings(_repoDistributed, new GitExtSettingsCache(_repoLocalConfigFilePath), SettingLevel.Local);
            _effective       = new RepoDistSettings(_repoLocal, new GitExtSettingsCache(null), SettingLevel.Effective);
        }
        public void SetUp()
        {
            _repo1 = new GitModuleTestHelper("repo1");
            _repo2 = new GitModuleTestHelper("repo2");
            _repo3 = new GitModuleTestHelper("repo3");

            _repo2.AddSubmodule(_repo3, "repo3");
            _repo1.AddSubmodule(_repo2, "repo2");
            var submodules = _repo1.GetSubmodulesRecursive();

            _repo1Module = _repo1.Module;
            _repo2Module = submodules.ElementAt(0);
            _repo3Module = submodules.ElementAt(1);

            // Use the singleton provider, which is also used by the left panel, so we can synchronize on updates
            _provider = SubmoduleStatusProvider.Default;

            _commands = new GitUICommands(_repo1Module);
        }
        public void Setup()
        {
            _testHelper = new GitModuleTestHelper();

            var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level1_repogit_GitExtensions.settings.xml");

            _level1 = _testHelper.CreateRepoFile(".git", "GitExtensions.settings", content);
            content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level2_repodist_GitExtensions.settings.xml");
            _level2 = _testHelper.CreateFile(_testHelper.TemporaryPath + "/RoamingProfile", "GitExtensions.settings", content);
            content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.level3_roaming_GitExtensions.settings.xml");
            _level3 = _testHelper.CreateRepoFile("GitExtensions.settings", content);

            _userRoaming     = new RepoDistSettings(null, new GitExtSettingsCache(_level3));
            _repoDistributed = new RepoDistSettings(_userRoaming, new GitExtSettingsCache(_level2));
            _repoLocal       = new RepoDistSettings(_repoDistributed, new GitExtSettingsCache(_level1));

            _externalLinksStorage = Substitute.For <IExternalLinksStorage>();

            _provider = new ConfiguredLinkDefinitionsProvider(_externalLinksStorage);
        }
Esempio n. 17
0
        public void FileViewer_highlight_selected_text_when_enabled()
        {
            const string textToSelect       = "Selected";
            const string selectedLinePrefix = "2:";
            const string sampleText         =
                "0\n" +
                "1:Selected\n" +
                "2:\n" +
                "3:Selected\n" +
                "4:";

            using var testHelper = new GitModuleTestHelper();
            var uiCommands = new GitUICommands(testHelper.Module);

            _uiCommandsSource.UICommands.Returns(x => uiCommands);
            _fileViewer.UICommandsSource = _uiCommandsSource;
            _fileViewer.GetTestAccessor().FileViewerInternal.SetText(sampleText, null);
            SelectionManager selectionManager = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.SelectionManager;

            // act
            selectionManager.SetSelection(new TextLocation(selectedLinePrefix.Length, 1), new TextLocation(selectedLinePrefix.Length + textToSelect.Length, 1));

            // assert
            selectionManager.SelectedText.Should().Be(textToSelect);
            selectionManager.SelectionCollection.Single().StartPosition.Line.Should().Be(1);
            int caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;

            caretOffset.Should().Be(0, "Caret position should be in default state");

            _fileViewer.GetTestAccessor().FileViewerInternal.GoToNextOccurrence();
            caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
            caretOffset.Should().Be(4, $"Caret should have been moved to the first occurrence of '{textToSelect}'");

            _fileViewer.GetTestAccessor().FileViewerInternal.GoToNextOccurrence();
            caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
            caretOffset.Should().Be(18, "Caret should have been moved to the second occurence of '" + textToSelect + "'");

            _fileViewer.GetTestAccessor().FileViewerInternal.GoToPreviousOccurrence();
            caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
            caretOffset.Should().Be(4, "Caret should have been moved back to the first occurence of '" + textToSelect + "'");
        }
Esempio n. 18
0
        public void Resolve_submodule_real_filesystem()
        {
            using var helper = new GitModuleTestHelper();
            helper.CreateFile(helper.Module.WorkingDir, ".gitmodules", @"[submodule ""Externals/NBug""]
    path = Externals/NBug
    url = https://github.com/gitextensions/NBug.git
[submodule ""Externals/Git.hub""]
    path = Externals/Git.hub
    url = https://github.com/gitextensions/Git.hub.gitk");

            var submoduleGitHub = Path.Combine(helper.Module.WorkingDir, "Externals", "Git.hub");
            var submoduleNBug   = Path.Combine(helper.Module.WorkingDir, "Externals", "NBug");
            var submoduleGitHubWorkingDirGitDir = Path.Combine(helper.Module.WorkingDirGitDir, "modules", "Externals", "Git.hub");
            var submoduleNbugWorkingDirGitDir   = Path.Combine(helper.Module.WorkingDirGitDir, "modules", "Externals", "NBug");

            helper.CreateFile(submoduleGitHub, ".git", "gitdir: ../../.git/modules/Externals/Git.hub");
            helper.CreateFile(submoduleNBug, ".git", "gitdir: ../../.git/modules/Externals/NBug");
            helper.CreateFile(helper.Module.WorkingDirGitDir, IndexLock, "");
            helper.CreateFile(submoduleGitHubWorkingDirGitDir, IndexLock, "");

            _manager = new IndexLockManager(helper.Module);

            var indexLock = Path.Combine(helper.Module.WorkingDirGitDir, IndexLock);

            File.Exists(indexLock).Should().BeTrue();
            var gitHubIndexLock = Path.Combine(submoduleGitHubWorkingDirGitDir, IndexLock);

            File.Exists(gitHubIndexLock).Should().BeTrue();
            var nbugIndexLock = Path.Combine(submoduleNbugWorkingDirGitDir, IndexLock);

            File.Exists(nbugIndexLock).Should().BeFalse();

            _manager.UnlockIndex(true);

            File.Exists(indexLock).Should().BeFalse();
            File.Exists(gitHubIndexLock).Should().BeFalse();
            File.Exists(nbugIndexLock).Should().BeFalse();
        }
Esempio n. 19
0
        public void SetUp()
        {
            _repo1 = new GitModuleTestHelper("repo1");
            _repo2 = new GitModuleTestHelper("repo2");
            _repo3 = new GitModuleTestHelper("repo3");

            _repo2.AddSubmodule(_repo3, "repo3");
            _repo1.AddSubmodule(_repo2, "repo2");
            var submodules = _repo1.GetSubmodulesRecursive();

            _repo1Module = _repo1.Module;
            _repo2Module = submodules.ElementAt(0);
            _repo3Module = submodules.ElementAt(1);

            // Use the singleton provider, which is also used by the left panel, so we can synchronize on updates
            _provider = SubmoduleStatusProvider.Default;

            _commands = new GitUICommands(_repo1Module);

            ExportProvider mefExportProvider = _composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
        public ReferenceRepository()
        {
            _moduleTestHelper = new GitModuleTestHelper();

            CreateCommit("A commit message", "A");
        }
Esempio n. 21
0
 public void SetUp()
 {
     _repo1    = new GitModuleTestHelper("repo1");
     _commands = new GitUICommands(_repo1.Module);
 }