Example #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());
        }