Exemplo n.º 1
0
        public virtual void CommitNewSubmodule()
        {
            Git git = new Git(db);

            WriteTrashFile("file.txt", "content");
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit           commit  = git.Commit().SetMessage("create file").Call();
            SubmoduleAddCommand command = new SubmoduleAddCommand(db);
            string path = "sub";

            command.SetPath(path);
            string uri = db.Directory.ToURI().ToString();

            command.SetURI(uri);
            Repository repo = command.Call();

            NUnit.Framework.Assert.IsNotNull(repo);
            AddRepoToClose(repo);
            SubmoduleWalk generator = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.AreEqual(path, generator.GetPath());
            NUnit.Framework.Assert.AreEqual(commit, generator.GetObjectId());
            NUnit.Framework.Assert.AreEqual(uri, generator.GetModulesUrl());
            NUnit.Framework.Assert.AreEqual(path, generator.GetModulesPath());
            NUnit.Framework.Assert.AreEqual(uri, generator.GetConfigUrl());
            Repository subModRepo = generator.GetRepository();

            AddRepoToClose(subModRepo);
            NUnit.Framework.Assert.IsNotNull(subModRepo);
            NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD));
            RevCommit submoduleCommit = git.Commit().SetMessage("submodule add").SetOnly(path
                                                                                         ).Call();

            NUnit.Framework.Assert.IsNotNull(submoduleCommit);
            TreeWalk walk = new TreeWalk(db);

            walk.AddTree(commit.Tree);
            walk.AddTree(submoduleCommit.Tree);
            walk.Filter = TreeFilter.ANY_DIFF;
            IList <DiffEntry> diffs = DiffEntry.Scan(walk);

            NUnit.Framework.Assert.AreEqual(1, diffs.Count);
            DiffEntry subDiff = diffs[0];

            NUnit.Framework.Assert.AreEqual(FileMode.MISSING, subDiff.GetOldMode());
            NUnit.Framework.Assert.AreEqual(FileMode.GITLINK, subDiff.GetNewMode());
            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, subDiff.GetOldId().ToObjectId());
            NUnit.Framework.Assert.AreEqual(commit, subDiff.GetNewId().ToObjectId());
            NUnit.Framework.Assert.AreEqual(path, subDiff.GetNewPath());
        }
Exemplo n.º 2
0
        public virtual void TestCloneRepositoryWithSubmodules()
        {
            git.Checkout().SetName(Constants.MASTER).Call();
            string file = "file.txt";

            WriteTrashFile(file, "content");
            git.Add().AddFilepattern(file).Call();
            RevCommit           commit  = git.Commit().SetMessage("create file").Call();
            SubmoduleAddCommand command = new SubmoduleAddCommand(db);
            string path = "sub";

            command.SetPath(path);
            string uri = db.Directory.ToURI().ToString();

            command.SetURI(uri);
            Repository repo = command.Call();

            NUnit.Framework.Assert.IsNotNull(repo);
            AddRepoToClose(repo);
            git.Add().AddFilepattern(path).AddFilepattern(Constants.DOT_GIT_MODULES).Call();
            git.Commit().SetMessage("adding submodule").Call();
            FilePath     directory = CreateTempDirectory("testCloneRepositoryWithSubmodules");
            CloneCommand clone     = Git.CloneRepository();

            clone.SetDirectory(directory);
            clone.SetCloneSubmodules(true);
            clone.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            Git git2 = clone.Call();

            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsNotNull(git2);
            NUnit.Framework.Assert.AreEqual(Constants.MASTER, git2.GetRepository().GetBranch(
                                                ));
            NUnit.Framework.Assert.IsTrue(new FilePath(git2.GetRepository().WorkTree, path +
                                                       FilePath.separatorChar + file).Exists());
            SubmoduleStatusCommand status = new SubmoduleStatusCommand(git2.GetRepository());
            IDictionary <string, SubmoduleStatus> statuses = status.Call();
            SubmoduleStatus pathStatus = statuses.Get(path);

            NUnit.Framework.Assert.IsNotNull(pathStatus);
            NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.INITIALIZED, pathStatus.GetType
                                                ());
            NUnit.Framework.Assert.AreEqual(commit, pathStatus.GetHeadId());
            NUnit.Framework.Assert.AreEqual(commit, pathStatus.GetIndexId());
        }