Ejemplo n.º 1
0
        public virtual void AddSubmoduleWithRelativeUri()
        {
            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";
            string uri  = "./.git";

            command.SetPath(path);
            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());
            string fullUri = db.Directory.GetAbsolutePath();

            if (FilePath.separatorChar == '\\')
            {
                fullUri = fullUri.Replace('\\', '/');
            }
            NUnit.Framework.Assert.AreEqual(fullUri, generator.GetConfigUrl());
            Repository subModRepo = generator.GetRepository();

            AddRepoToClose(subModRepo);
            NUnit.Framework.Assert.IsNotNull(subModRepo);
            NUnit.Framework.Assert.AreEqual(fullUri, subModRepo.GetConfig().GetString(ConfigConstants
                                                                                      .CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL
                                                                                      ));
            NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD));
            Status status = Git.Wrap(db).Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(Constants.DOT_GIT_MODULES
                                                                     ));
            NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path));
        }
Ejemplo n.º 2
0
 public virtual void AddExistentSubmodule()
 {
     ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
     string path = "sub";
     DirCache cache = db.LockDirCache();
     DirCacheEditor editor = cache.Editor();
     editor.Add(new _PathEdit_153(id, path));
     editor.Commit();
     SubmoduleAddCommand command = new SubmoduleAddCommand(db);
     command.SetPath(path);
     command.SetURI("git://server/repo.git");
     try
     {
         command.Call();
         NUnit.Framework.Assert.Fail("Exception not thrown");
     }
     catch (JGitInternalException e)
     {
         NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().submoduleExists
             , path), e.Message);
     }
 }
Ejemplo n.º 3
0
        public virtual void AddSubmoduleWithExistingSubmoduleDefined()
        {
            string          path1         = "sub1";
            string          url1          = "git://server/repo1.git";
            string          path2         = "sub2";
            FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
                                                                             .DOT_GIT_MODULES), db.FileSystem);

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path1, ConfigConstants
                                    .CONFIG_KEY_PATH, path1);
            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path1, ConfigConstants
                                    .CONFIG_KEY_URL, url1);
            modulesConfig.Save();
            Git git = new Git(db);

            WriteTrashFile("file.txt", "content");
            git.Add().AddFilepattern("file.txt").Call();
            NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("create file").Call());
            SubmoduleAddCommand command = new SubmoduleAddCommand(db);

            command.SetPath(path2);
            string url2 = db.Directory.ToURI().ToString();

            command.SetURI(url2);
            Repository r = command.Call();

            NUnit.Framework.Assert.IsNotNull(r);
            AddRepoToClose(r);
            modulesConfig.Load();
            NUnit.Framework.Assert.AreEqual(path1, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
                                                                           , path1, ConfigConstants.CONFIG_KEY_PATH));
            NUnit.Framework.Assert.AreEqual(url1, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
                                                                          , path1, ConfigConstants.CONFIG_KEY_URL));
            NUnit.Framework.Assert.AreEqual(path2, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
                                                                           , path2, ConfigConstants.CONFIG_KEY_PATH));
            NUnit.Framework.Assert.AreEqual(url2, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
                                                                          , path2, ConfigConstants.CONFIG_KEY_URL));
        }
Ejemplo n.º 4
0
        public virtual void AddSubmodule()
        {
            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));
            Status status = Git.Wrap(db).Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(Constants.DOT_GIT_MODULES
                                                                     ));
            NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path));
        }
Ejemplo n.º 5
0
        public virtual void AddExistentSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_160(id, path));
            editor.Commit();
            SubmoduleAddCommand command = new SubmoduleAddCommand(db);

            command.SetPath(path);
            command.SetURI("git://server/repo.git");
            try
            {
                command.Call().Close();
                NUnit.Framework.Assert.Fail("Exception not thrown");
            }
            catch (JGitInternalException e)
            {
                NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().submoduleExists
                                                                     , path), e.Message);
            }
        }
Ejemplo n.º 6
0
 public virtual void CommitSubmoduleUpdate()
 {
     Git git = new Git(db);
     WriteTrashFile("file.txt", "content");
     git.Add().AddFilepattern("file.txt").Call();
     RevCommit commit = git.Commit().SetMessage("create file").Call();
     WriteTrashFile("file.txt", "content2");
     git.Add().AddFilepattern("file.txt").Call();
     RevCommit commit2 = git.Commit().SetMessage("edit 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(commit2, 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(commit2, repo.Resolve(Constants.HEAD));
     RevCommit submoduleAddCommit = git.Commit().SetMessage("submodule add").SetOnly(path
         ).Call();
     NUnit.Framework.Assert.IsNotNull(submoduleAddCommit);
     RefUpdate update = repo.UpdateRef(Constants.HEAD);
     update.SetNewObjectId(commit);
     NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, update.ForceUpdate());
     RevCommit submoduleEditCommit = git.Commit().SetMessage("submodule add").SetOnly(
         path).Call();
     NUnit.Framework.Assert.IsNotNull(submoduleEditCommit);
     TreeWalk walk = new TreeWalk(db);
     walk.AddTree(submoduleAddCommit.Tree);
     walk.AddTree(submoduleEditCommit.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.GITLINK, subDiff.GetOldMode());
     NUnit.Framework.Assert.AreEqual(FileMode.GITLINK, subDiff.GetNewMode());
     NUnit.Framework.Assert.AreEqual(commit2, subDiff.GetOldId().ToObjectId());
     NUnit.Framework.Assert.AreEqual(commit, subDiff.GetNewId().ToObjectId());
     NUnit.Framework.Assert.AreEqual(path, subDiff.GetNewPath());
     NUnit.Framework.Assert.AreEqual(path, subDiff.GetOldPath());
 }
Ejemplo n.º 7
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());
 }
Ejemplo n.º 8
0
 public virtual void AddSubmodule()
 {
     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);
     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());
     NUnit.Framework.Assert.IsNotNull(generator.GetRepository());
     NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD));
     Status status = Git.Wrap(db).Status().Call();
     NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(Constants.DOT_GIT_MODULES
         ));
     NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path));
 }
Ejemplo n.º 9
0
 public virtual void AddSubmoduleWithRelativeUri()
 {
     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";
     string uri = "./.git";
     command.SetPath(path);
     command.SetURI(uri);
     Repository repo = command.Call();
     NUnit.Framework.Assert.IsNotNull(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());
     string fullUri = db.Directory.GetAbsolutePath();
     if (FilePath.separatorChar == '\\')
     {
         fullUri = fullUri.Replace('\\', '/');
     }
     NUnit.Framework.Assert.AreEqual(fullUri, generator.GetConfigUrl());
     NUnit.Framework.Assert.IsNotNull(generator.GetRepository());
     NUnit.Framework.Assert.AreEqual(fullUri, generator.GetRepository().GetConfig().GetString
         (ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants
         .CONFIG_KEY_URL));
     NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD));
     Status status = Git.Wrap(db).Status().Call();
     NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(Constants.DOT_GIT_MODULES
         ));
     NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path));
 }
Ejemplo n.º 10
0
 public virtual void TestSubmoduleDeleteNotStagedWithUpdate()
 {
     Git git = new Git(db);
     WriteTrashFile("file.txt", "content");
     git.Add().AddFilepattern("file.txt").Call();
     NUnit.Framework.Assert.IsNotNull(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);
     NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("add submodule").Call());
     NUnit.Framework.Assert.IsTrue(git.Status().Call().IsClean());
     FileUtils.Delete(repo.WorkTree, FileUtils.RECURSIVE);
     FileUtils.Mkdir(new FilePath(db.WorkTree, path), false);
     NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern(".").SetUpdate(true).Call
         ());
     Status status = git.Status().Call();
     NUnit.Framework.Assert.IsFalse(status.IsClean());
     NUnit.Framework.Assert.IsTrue(status.GetAdded().IsEmpty());
     NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
     NUnit.Framework.Assert.IsTrue(status.GetRemoved().IsEmpty());
     NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
     NUnit.Framework.Assert.IsTrue(status.GetModified().IsEmpty());
     NUnit.Framework.Assert.AreEqual(1, status.GetMissing().Count);
     NUnit.Framework.Assert.AreEqual(path, status.GetMissing().Iterator().Next());
 }
Ejemplo n.º 11
0
 public virtual void AddSubmoduleWithExistingSubmoduleDefined()
 {
     string path1 = "sub1";
     string url1 = "git://server/repo1.git";
     string path2 = "sub2";
     FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
         .DOT_GIT_MODULES), db.FileSystem);
     modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path1, ConfigConstants
         .CONFIG_KEY_PATH, path1);
     modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path1, ConfigConstants
         .CONFIG_KEY_URL, url1);
     modulesConfig.Save();
     Git git = new Git(db);
     WriteTrashFile("file.txt", "content");
     git.Add().AddFilepattern("file.txt").Call();
     NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("create file").Call());
     SubmoduleAddCommand command = new SubmoduleAddCommand(db);
     command.SetPath(path2);
     string url2 = db.Directory.ToURI().ToString();
     command.SetURI(url2);
     NUnit.Framework.Assert.IsNotNull(command.Call());
     modulesConfig.Load();
     NUnit.Framework.Assert.AreEqual(path1, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
         , path1, ConfigConstants.CONFIG_KEY_PATH));
     NUnit.Framework.Assert.AreEqual(url1, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
         , path1, ConfigConstants.CONFIG_KEY_URL));
     NUnit.Framework.Assert.AreEqual(path2, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
         , path2, ConfigConstants.CONFIG_KEY_PATH));
     NUnit.Framework.Assert.AreEqual(url2, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION
         , path2, ConfigConstants.CONFIG_KEY_URL));
 }