Exemplo n.º 1
0
        public virtual void RepositoryWithMissingSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_93(id, path));
            editor.Commit();
            SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
            IDictionary <string, SubmoduleStatus> statuses = command.Call();

            NUnit.Framework.Assert.IsNotNull(statuses);
            NUnit.Framework.Assert.AreEqual(1, statuses.Count);
            KeyValuePair <string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
                                                                ();

            NUnit.Framework.Assert.IsNotNull(module);
            NUnit.Framework.Assert.AreEqual(path, module.Key);
            SubmoduleStatus status = module.Value;

            NUnit.Framework.Assert.IsNotNull(status);
            NUnit.Framework.Assert.AreEqual(path, status.GetPath());
            NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
            NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.MISSING, status.GetType());
        }
Exemplo n.º 2
0
		public virtual void RepositoryWithNoSubmodules()
		{
			SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
			IDictionary<string, SubmoduleStatus> statuses = command.Call();
			NUnit.Framework.Assert.IsNotNull(statuses);
			NUnit.Framework.Assert.IsTrue(statuses.IsEmpty());
		}
Exemplo n.º 3
0
        public virtual void RepositoryWithUninitializedSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_125(id, path));
            editor.Commit();
            FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
                                                                             .DOT_GIT_MODULES), db.FileSystem);

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_PATH, path);
            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, "git://server/repo.git");
            modulesConfig.Save();
            SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
            IDictionary <string, SubmoduleStatus> statuses = command.Call();

            NUnit.Framework.Assert.IsNotNull(statuses);
            NUnit.Framework.Assert.AreEqual(1, statuses.Count);
            KeyValuePair <string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
                                                                ();

            NUnit.Framework.Assert.IsNotNull(module);
            NUnit.Framework.Assert.AreEqual(path, module.Key);
            SubmoduleStatus status = module.Value;

            NUnit.Framework.Assert.IsNotNull(status);
            NUnit.Framework.Assert.AreEqual(path, status.GetPath());
            NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
            NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.UNINITIALIZED, status.GetType
                                                ());
        }
Exemplo n.º 4
0
        public virtual void RepositoryWithNoSubmodules()
        {
            SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
            IDictionary <string, SubmoduleStatus> statuses = command.Call();

            NUnit.Framework.Assert.IsNotNull(statuses);
            NUnit.Framework.Assert.IsTrue(statuses.IsEmpty());
        }
Exemplo n.º 5
0
        public virtual void RepositoryWithDifferentRevCheckedOutSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_317(id, path));
            editor.Commit();
            string       url    = "git://server/repo.git";
            StoredConfig config = ((FileBasedConfig)db.GetConfig());

            config.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.
                             CONFIG_KEY_URL, url);
            config.Save();
            FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
                                                                             .DOT_GIT_MODULES), db.FileSystem);

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_PATH, path);
            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            modulesConfig.Save();
            Repository subRepo = Git.Init().SetBare(false).SetDirectory(new FilePath(db.WorkTree
                                                                                     , path)).Call().GetRepository();

            NUnit.Framework.Assert.IsNotNull(subRepo);
            RefUpdate update = subRepo.UpdateRef(Constants.HEAD, true);

            update.SetNewObjectId(ObjectId.FromString("aaaa0000aaaa0000aaaa0000aaaa0000aaaa0000"
                                                      ));
            update.ForceUpdate();
            SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
            IDictionary <string, SubmoduleStatus> statuses = command.Call();

            NUnit.Framework.Assert.IsNotNull(statuses);
            NUnit.Framework.Assert.AreEqual(1, statuses.Count);
            KeyValuePair <string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
                                                                ();

            NUnit.Framework.Assert.IsNotNull(module);
            NUnit.Framework.Assert.AreEqual(path, module.Key);
            SubmoduleStatus status = module.Value;

            NUnit.Framework.Assert.IsNotNull(status);
            NUnit.Framework.Assert.AreEqual(path, status.GetPath());
            NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
            NUnit.Framework.Assert.AreEqual(update.GetNewObjectId(), status.GetHeadId());
            NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.REV_CHECKED_OUT, status.GetType
                                                ());
        }
Exemplo n.º 6
0
		public virtual void RepositoryWithMissingSubmodule()
		{
			ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
			string path = "sub";
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			editor.Add(new _PathEdit_93(id, path));
			editor.Commit();
			SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
			IDictionary<string, SubmoduleStatus> statuses = command.Call();
			NUnit.Framework.Assert.IsNotNull(statuses);
			NUnit.Framework.Assert.AreEqual(1, statuses.Count);
			KeyValuePair<string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
				();
			NUnit.Framework.Assert.IsNotNull(module);
			NUnit.Framework.Assert.AreEqual(path, module.Key);
			SubmoduleStatus status = module.Value;
			NUnit.Framework.Assert.IsNotNull(status);
			NUnit.Framework.Assert.AreEqual(path, status.GetPath());
			NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
			NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.MISSING, status.GetType());
		}
Exemplo n.º 7
0
		public virtual void RepositoryWithDifferentRevCheckedOutSubmodule()
		{
			ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
			string path = "sub";
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			editor.Add(new _PathEdit_317(id, path));
			editor.Commit();
			string url = "git://server/repo.git";
			StoredConfig config = ((FileBasedConfig)db.GetConfig());
			config.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.
				CONFIG_KEY_URL, url);
			config.Save();
			FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
				.DOT_GIT_MODULES), db.FileSystem);
			modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
				.CONFIG_KEY_PATH, path);
			modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
				.CONFIG_KEY_URL, url);
			modulesConfig.Save();
			Repository subRepo = Git.Init().SetBare(false).SetDirectory(new FilePath(db.WorkTree
				, path)).Call().GetRepository();
			NUnit.Framework.Assert.IsNotNull(subRepo);
			RefUpdate update = subRepo.UpdateRef(Constants.HEAD, true);
			update.SetNewObjectId(ObjectId.FromString("aaaa0000aaaa0000aaaa0000aaaa0000aaaa0000"
				));
			update.ForceUpdate();
			SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
			IDictionary<string, SubmoduleStatus> statuses = command.Call();
			NUnit.Framework.Assert.IsNotNull(statuses);
			NUnit.Framework.Assert.AreEqual(1, statuses.Count);
			KeyValuePair<string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
				();
			NUnit.Framework.Assert.IsNotNull(module);
			NUnit.Framework.Assert.AreEqual(path, module.Key);
			SubmoduleStatus status = module.Value;
			NUnit.Framework.Assert.IsNotNull(status);
			NUnit.Framework.Assert.AreEqual(path, status.GetPath());
			NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
			NUnit.Framework.Assert.AreEqual(update.GetNewObjectId(), status.GetHeadId());
			NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.REV_CHECKED_OUT, status.GetType
				());
		}
Exemplo n.º 8
0
		public virtual void RepositoryWithNoSubmoduleRepository()
		{
			ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
			string path = "sub";
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			editor.Add(new _PathEdit_216(id, path));
			editor.Commit();
			string url = "git://server/repo.git";
			StoredConfig config = ((FileBasedConfig)db.GetConfig());
			config.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.
				CONFIG_KEY_URL, url);
			config.Save();
			FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
				.DOT_GIT_MODULES), db.FileSystem);
			modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
				.CONFIG_KEY_PATH, path);
			modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
				.CONFIG_KEY_URL, url);
			modulesConfig.Save();
			SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
			IDictionary<string, SubmoduleStatus> statuses = command.Call();
			NUnit.Framework.Assert.IsNotNull(statuses);
			NUnit.Framework.Assert.AreEqual(1, statuses.Count);
			KeyValuePair<string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
				();
			NUnit.Framework.Assert.IsNotNull(module);
			NUnit.Framework.Assert.AreEqual(path, module.Key);
			SubmoduleStatus status = module.Value;
			NUnit.Framework.Assert.IsNotNull(status);
			NUnit.Framework.Assert.AreEqual(path, status.GetPath());
			NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
			NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.UNINITIALIZED, status.GetType
				());
		}
Exemplo n.º 9
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);
     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());
 }
Exemplo n.º 10
0
		public virtual void TestCloneRepositoryWithNestedSubmodules()
		{
			git.Checkout().SetName(Constants.MASTER).Call();
			// Create submodule 1
			FilePath submodule1 = CreateTempDirectory("testCloneRepositoryWithNestedSubmodules1"
				);
			Git sub1Git = Git.Init().SetDirectory(submodule1).Call();
			NUnit.Framework.Assert.IsNotNull(sub1Git);
			Repository sub1 = sub1Git.GetRepository();
			NUnit.Framework.Assert.IsNotNull(sub1);
			AddRepoToClose(sub1);
			string file = "file.txt";
			string path = "sub";
			Write(new FilePath(sub1.WorkTree, file), "content");
			sub1Git.Add().AddFilepattern(file).Call();
			RevCommit commit = sub1Git.Commit().SetMessage("create file").Call();
			NUnit.Framework.Assert.IsNotNull(commit);
			// Create submodule 2
			FilePath submodule2 = CreateTempDirectory("testCloneRepositoryWithNestedSubmodules2"
				);
			Git sub2Git = Git.Init().SetDirectory(submodule2).Call();
			NUnit.Framework.Assert.IsNotNull(sub2Git);
			Repository sub2 = sub2Git.GetRepository();
			NUnit.Framework.Assert.IsNotNull(sub2);
			AddRepoToClose(sub2);
			Write(new FilePath(sub2.WorkTree, file), "content");
			sub2Git.Add().AddFilepattern(file).Call();
			RevCommit sub2Head = sub2Git.Commit().SetMessage("create file").Call();
			NUnit.Framework.Assert.IsNotNull(sub2Head);
			// Add submodule 2 to submodule 1
			Repository r = sub1Git.SubmoduleAdd().SetPath(path).SetURI(sub2.Directory.ToURI()
				.ToString()).Call();
			NUnit.Framework.Assert.IsNotNull(r);
			AddRepoToClose(r);
			RevCommit sub1Head = sub1Git.Commit().SetAll(true).SetMessage("Adding submodule")
				.Call();
			NUnit.Framework.Assert.IsNotNull(sub1Head);
			// Add submodule 1 to default repository
			r = git.SubmoduleAdd().SetPath(path).SetURI(sub1.Directory.ToURI().ToString()).Call
				();
			NUnit.Framework.Assert.IsNotNull(r);
			AddRepoToClose(r);
			NUnit.Framework.Assert.IsNotNull(git.Commit().SetAll(true).SetMessage("Adding submodule"
				).Call());
			// Clone default repository and include submodules
			FilePath directory = CreateTempDirectory("testCloneRepositoryWithNestedSubmodules"
				);
			CloneCommand clone = Git.CloneRepository();
			clone.SetDirectory(directory);
			clone.SetCloneSubmodules(true);
			clone.SetURI(git.GetRepository().Directory.ToURI().ToString());
			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());
			NUnit.Framework.Assert.IsTrue(new FilePath(git2.GetRepository().WorkTree, path + 
				FilePath.separatorChar + 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(sub1Head, pathStatus.GetHeadId());
			NUnit.Framework.Assert.AreEqual(sub1Head, pathStatus.GetIndexId());
			SubmoduleWalk walk = SubmoduleWalk.ForIndex(git2.GetRepository());
			NUnit.Framework.Assert.IsTrue(walk.Next());
			Repository clonedSub1 = walk.GetRepository();
			AddRepoToClose(clonedSub1);
			NUnit.Framework.Assert.IsNotNull(clonedSub1);
			status = new SubmoduleStatusCommand(clonedSub1);
			statuses = status.Call();
			pathStatus = statuses.Get(path);
			NUnit.Framework.Assert.IsNotNull(pathStatus);
			NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.INITIALIZED, pathStatus.GetType
				());
			NUnit.Framework.Assert.AreEqual(sub2Head, pathStatus.GetHeadId());
			NUnit.Framework.Assert.AreEqual(sub2Head, pathStatus.GetIndexId());
			NUnit.Framework.Assert.IsFalse(walk.Next());
		}