public virtual void TestTreeIteratorWithGitmodules() { ObjectId subId = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); string path = "sub"; Config gitmodules = new Config(); gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_PATH, "sub"); gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_URL, "git://example.com/sub"); RevCommit commit = testDb.GetRevWalk().ParseCommit(testDb.Commit().NoParents().Add (Constants.DOT_GIT_MODULES, gitmodules.ToText()).Edit(new _PathEdit_397(subId, path )).Create()); CanonicalTreeParser p = new CanonicalTreeParser(); p.Reset(testDb.GetRevWalk().GetObjectReader(), commit.Tree); SubmoduleWalk gen = SubmoduleWalk.ForPath(db, p, "sub"); NUnit.Framework.Assert.AreEqual(path, gen.GetPath()); NUnit.Framework.Assert.AreEqual(subId, gen.GetObjectId()); NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory ()); NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate()); NUnit.Framework.Assert.IsNull(gen.GetConfigUrl()); NUnit.Framework.Assert.AreEqual("sub", gen.GetModulesPath()); NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate()); NUnit.Framework.Assert.AreEqual("git://example.com/sub", gen.GetModulesUrl()); NUnit.Framework.Assert.IsNull(gen.GetRepository()); NUnit.Framework.Assert.IsFalse(gen.Next()); }
public virtual void RepositoryWithRootLevelSubmoduleRelativeRef() { ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); string path = "sub"; FilePath dotGit = new FilePath(db.WorkTree, path + FilePath.separatorChar + Constants .DOT_GIT); if (!dotGit.GetParentFile().Exists()) { dotGit.GetParentFile().Mkdirs(); } FilePath modulesGitDir = new FilePath(db.Directory, "modules" + FilePath.separatorChar + path); new FileWriter(dotGit).Append("gitdir: " + "../" + Constants.DOT_GIT + "/modules/" + path).Close(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.SetWorkTree(new FilePath(db.WorkTree, path)); builder.Build().Create(); DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_203(id, path)); editor.Commit(); SubmoduleWalk gen = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(gen.Next()); NUnit.Framework.Assert.AreEqual(path, gen.GetPath()); NUnit.Framework.Assert.AreEqual(id, gen.GetObjectId()); NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory ()); NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate()); NUnit.Framework.Assert.IsNull(gen.GetConfigUrl()); NUnit.Framework.Assert.IsNull(gen.GetModulesPath()); NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate()); NUnit.Framework.Assert.IsNull(gen.GetModulesUrl()); Repository subRepo = gen.GetRepository(); AddRepoToClose(subRepo); NUnit.Framework.Assert.IsNotNull(subRepo); NUnit.Framework.Assert.AreEqual(modulesGitDir, subRepo.Directory); NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), subRepo.WorkTree ); NUnit.Framework.Assert.IsFalse(gen.Next()); }
public virtual void IndexWithGitmodules() { ObjectId subId = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); string path = "sub"; Config gitmodules = new Config(); gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_PATH, "sub"); // Different config in the index should be overridden by the working tree. gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_URL, "git://example.com/bad"); RevBlob gitmodulesBlob = testDb.Blob(gitmodules.ToText()); gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_URL, "git://example.com/sub"); WriteTrashFile(Constants.DOT_GIT_MODULES, gitmodules.ToText()); DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_315(subId, path)); editor.Add(new _PathEdit_322(gitmodulesBlob, Constants.DOT_GIT_MODULES)); editor.Commit(); SubmoduleWalk gen = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(gen.Next()); NUnit.Framework.Assert.AreEqual(path, gen.GetPath()); NUnit.Framework.Assert.AreEqual(subId, gen.GetObjectId()); NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory ()); NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate()); NUnit.Framework.Assert.IsNull(gen.GetConfigUrl()); NUnit.Framework.Assert.AreEqual("sub", gen.GetModulesPath()); NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate()); NUnit.Framework.Assert.AreEqual("git://example.com/sub", gen.GetModulesUrl()); NUnit.Framework.Assert.IsNull(gen.GetRepository()); NUnit.Framework.Assert.IsFalse(gen.Next()); }
public virtual void RepositoryWithRootLevelSubmodule() { ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); string path = "sub"; DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_108(id, path)); editor.Commit(); SubmoduleWalk gen = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(gen.Next()); NUnit.Framework.Assert.AreEqual(path, gen.GetPath()); NUnit.Framework.Assert.AreEqual(id, gen.GetObjectId()); NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory ()); NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate()); NUnit.Framework.Assert.IsNull(gen.GetConfigUrl()); NUnit.Framework.Assert.IsNull(gen.GetModulesPath()); NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate()); NUnit.Framework.Assert.IsNull(gen.GetModulesUrl()); NUnit.Framework.Assert.IsNull(gen.GetRepository()); NUnit.Framework.Assert.IsFalse(gen.Next()); }