Esempio n. 1
0
        public void GetUntrackedFiles_ProjectInMainRepoIncludesFilesInSubmodules()
        {
            string gitRoot = s_root.Replace('\\', '/');

            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                submodules: new[]
            {
                new TestSubmodule("1", "sub/1", "http://1.com", "1111111111111111111111111111111111111111"),
                new TestSubmodule("2", "sub/2", "http://2.com", "2222222222222222222222222222222222222222")
            },
                ignoredPaths: new[] { gitRoot + @"/c.cs", gitRoot + @"/p/d.cs", gitRoot + @"/sub/1/x.cs" });

            var subRoot1 = Path.Combine(s_root, "sub", "1");
            var subRoot2 = Path.Combine(s_root, "sub", "2");

            var subRepos = new Dictionary <string, TestRepository>()
            {
                { subRoot1, new TestRepository(subRoot1, commitSha: null, ignoredPaths: new[] { gitRoot + @"/sub/1/obj/a.cs" }) },
                { subRoot2, new TestRepository(subRoot2, commitSha: null, ignoredPaths: new[] { gitRoot + @"/sub/2/obj/b.cs" }) },
            };

            var actual = GitOperations.GetUntrackedFiles(repo,
                                                         new[]
            {
                new MockItem(@"c.cs"),                             // not ignored
                new MockItem(@"..\sub\1\x.cs"),                    // ignored in the main repository, but not in the submodule (which has a priority)
                new MockItem(@"../sub/2/obj/b.cs"),                // ignored in submodule #2
                new MockItem(@"d.cs"),                             // not ignored
                new MockItem(@"..\..\w.cs"),                       // outside of repo
                new MockItem(IsUnix ? "/d/w.cs" : @"D:\w.cs"),     // outside of repo
            },
                                                         projectDirectory: Path.Combine(s_root, "p"),
                                                         root => subRepos[root]);

            AssertEx.Equal(new[]
            {
                MockItem.AdjustSeparators("../sub/2/obj/b.cs"),
                MockItem.AdjustSeparators("d.cs"),
                MockItem.AdjustSeparators(@"..\..\w.cs"),
                MockItem.AdjustSeparators(IsUnix ? "/d/w.cs" : @"D:\w.cs")
            }, actual.Select(item => item.ItemSpec));
        }
        public void GetUntrackedFiles_ProjectInSubmodule()
        {
            string gitRoot = s_root.Replace('\\', '/');

            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                submodules: new[]
            {
                new TestSubmodule("1", "sub/1", "http://1.com", "1111111111111111111111111111111111111111"),
                new TestSubmodule("2", "sub/2", "http://2.com", "2222222222222222222222222222222222222222")
            },
                ignoredPaths: new[] { gitRoot + "/c.cs", gitRoot + "/sub/1/x.cs" });

            var subRoot1 = Path.Combine(s_root, "sub", "1");
            var subRoot2 = Path.Combine(s_root, "sub", "2");

            var subRepos = new Dictionary <string, TestRepository>()
            {
                { subRoot1, new TestRepository(subRoot1, commitSha: null, ignoredPaths: new[] { gitRoot + "/sub/1/obj/a.cs" }) },
                { subRoot2, new TestRepository(subRoot2, commitSha: null, ignoredPaths: new[] { gitRoot + "/sub/2/obj/b.cs" }) },
            };

            var actual = repo.GetUntrackedFiles(
                new[]
            {
                new MockItem(@"c.cs"),               // not ignored
                new MockItem(@"x.cs"),               // ignored in the main repository, but not in the submodule (which has a priority)
                new MockItem(@"obj\a.cs"),           // ignored in submodule #1
                new MockItem(@"obj\b.cs"),           // not ignored
                new MockItem(@"..\2\obj\b.cs"),      // ignored in submodule #2
                new MockItem(@"..\..\c.cs"),         // ignored in main repo
            },
                projectDirectory: subRoot1,
                root => subRepos[root]);

            AssertEx.Equal(new[]
            {
                MockItem.AdjustSeparators(@"obj\a.cs"),
                MockItem.AdjustSeparators(@"..\2\obj\b.cs"),
                MockItem.AdjustSeparators(@"..\..\c.cs")
            }, actual.Select(item => item.ItemSpec));
        }
Esempio n. 3
0
        public void MinimalGitData()
        {
            using var temp = new TempRoot();
            var repoDir = temp.CreateDirectory();

            var gitDir = repoDir.CreateDirectory(".git");

            gitDir.CreateFile("HEAD").WriteAllText("1111111111111111111111111111111111111111");
            gitDir.CreateFile("config").WriteAllText(@"
[remote ""origin""]
url=http://github.com/test-org/test-repo
[submodule ""my submodule""]
url=https://github.com/test-org/test-sub
");
            gitDir.CreateDirectory("objects");
            gitDir.CreateDirectory("refs");
            repoDir.CreateFile(".gitignore").WriteAllText("ignore_this_*");

            // submodule:
            var gitModules = repoDir.CreateFile(".gitmodules").WriteAllText(@"
[submodule ""my submodule""]
  path = sub
  url = xyz
");

            var subDir = repoDir.CreateDirectory("sub");

            subDir.CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub");
            subDir.CreateFile(".gitignore").WriteAllText("ignore_in_submodule_*");

            var gitDirSub = gitDir.CreateDirectory("modules").CreateDirectory("sub");

            gitDirSub.CreateFile("HEAD").WriteAllText("2222222222222222222222222222222222222222");
            gitDirSub.CreateDirectory("objects");
            gitDirSub.CreateDirectory("refs");

            var repository = GitRepository.OpenRepository(repoDir.Path, GitEnvironment.Empty) !;

            Assert.Equal("http://github.com/test-org/test-repo", GitOperations.GetRepositoryUrl(repository, remoteName: null));
            Assert.Equal("1111111111111111111111111111111111111111", repository.GetHeadCommitSha());

            var warnings    = new List <(string, object?[])>();
            var sourceRoots = GitOperations.GetSourceRoots(repository, remoteName: null, (message, args) => warnings.Add((message, args)));

            AssertEx.Equal(new[]
            {
                $@"'{repoDir.Path}{s}' SourceControl='git' RevisionId='1111111111111111111111111111111111111111' ScmRepositoryUrl='http://github.com/test-org/test-repo'",
                $@"'{repoDir.Path}{s}sub{s}' SourceControl='git' RevisionId='2222222222222222222222222222222222222222' NestedRoot='sub/' ContainingRoot='{repoDir.Path}{s}' ScmRepositoryUrl='https://github.com/test-org/test-sub'",
            }, sourceRoots.Select(TestUtilities.InspectSourceRoot));

            AssertEx.Equal(new string[0], warnings.Select(TestUtilities.InspectDiagnostic));

            var files = new[]
            {
                new MockItem(@"ignore_this_a"),
                new MockItem(@"b"),
                new MockItem(@"ignore_this_c"),
                new MockItem(@"sub\ignore_in_submodule_d"),
            };

            var untrackedFiles = GitOperations.GetUntrackedFiles(repository, files, repoDir.Path);

            AssertEx.Equal(new[]
            {
                "ignore_this_a",
                "ignore_this_c",
                MockItem.AdjustSeparators(@"sub\ignore_in_submodule_d"),
            }, untrackedFiles.Select(item => item.ItemSpec));
        }