public virtual void TestFileRepository_ChangeEventsOnlyOnSave()
        {
            ConfigChangedEvent[] events = new ConfigChangedEvent[1];
            db.Listeners.AddConfigChangedListener(new _ConfigChangedListener_58(events));
            FileBasedConfig config = ((FileBasedConfig)db.GetConfig());

            NUnit.Framework.Assert.IsNull(events[0]);
            // set a value to some arbitrary key
            config.SetString("test", "section", "event", "value");
            // no changes until we save
            NUnit.Framework.Assert.IsNull(events[0]);
            config.Save();
            NUnit.Framework.Assert.IsNotNull(events[0]);
            // correct repository?
            NUnit.Framework.Assert.AreEqual(events[0].GetRepository(), db);
            // reset for the next test
            events[0] = null;
            // unset the value we have just set above
            config.Unset("test", "section", "event");
            // no changes until we save
            NUnit.Framework.Assert.IsNull(events[0]);
            config.Save();
            NUnit.Framework.Assert.IsNotNull(events[0]);
            // correct repository?
            NUnit.Framework.Assert.AreEqual(events[0].GetRepository(), db);
        }
        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
                                                ());
        }
        public virtual void ResolveInvalidParentUrl()
        {
            string          path   = AddSubmoduleToIndex();
            string          @base  = "no_slash";
            FileBasedConfig config = ((FileBasedConfig)db.GetConfig());

            config.SetString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME
                             , ConfigConstants.CONFIG_KEY_URL, @base);
            config.Save();
            SubmoduleWalk generator = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUrl());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUpdate());
            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);
            string url = "../sub.git";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            modulesConfig.Save();
            try
            {
                new SubmoduleInitCommand(db).Call();
                NUnit.Framework.Assert.Fail("Exception not thrown");
            }
            catch (JGitInternalException e)
            {
                NUnit.Framework.Assert.IsTrue(e.InnerException is IOException);
            }
        }
        public virtual void RepositoryWithUninitializedModule()
        {
            string        path      = AddSubmoduleToIndex();
            SubmoduleWalk generator = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUrl());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUpdate());
            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);
            string url = "git://server/repo.git";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            string update = "rebase";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_UPDATE, update);
            modulesConfig.Save();
            SubmoduleInitCommand command = new SubmoduleInitCommand(db);
            ICollection <string> modules = command.Call();

            NUnit.Framework.Assert.IsNotNull(modules);
            NUnit.Framework.Assert.AreEqual(1, modules.Count);
            NUnit.Framework.Assert.AreEqual(path, modules.Iterator().Next());
            generator = SubmoduleWalk.ForIndex(db);
            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.AreEqual(url, generator.GetConfigUrl());
            NUnit.Framework.Assert.AreEqual(update, generator.GetConfigUpdate());
        }
        public virtual void RepositoryWithUnconfiguredSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_137(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);
            string url = "git://server/repo.git";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            string update = "rebase";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_UPDATE, update);
            modulesConfig.Save();
            SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db);
            ICollection <string>   updated = command.Call();

            NUnit.Framework.Assert.IsNotNull(updated);
            NUnit.Framework.Assert.IsTrue(updated.IsEmpty());
        }
 /// <summary>Parse and load the repository specific configuration.</summary>
 /// <remarks>
 /// Parse and load the repository specific configuration.
 /// <p>
 /// The default implementation reads
 /// <code>gitDir/config</code>
 /// , or returns an
 /// empty configuration if gitDir was not set.
 /// </remarks>
 /// <returns>the repository's configuration.</returns>
 /// <exception cref="System.IO.IOException">the configuration is not available.</exception>
 protected internal virtual Config LoadConfig()
 {
     if (GetGitDir() != null)
     {
         // We only want the repository's configuration file, and not
         // the user file, as these parameters must be unique to this
         // repository and not inherited from other files.
         //
         FilePath        path = SafeFS().Resolve(GetGitDir(), Constants.CONFIG);
         FileBasedConfig cfg  = new FileBasedConfig(path, SafeFS());
         try
         {
             cfg.Load();
         }
         catch (ConfigInvalidException err)
         {
             throw new ArgumentException(MessageFormat.Format(JGitText.Get().repositoryConfigFileInvalid
                                                              , path.GetAbsolutePath(), err.Message));
         }
         return(cfg);
     }
     else
     {
         return(new Config());
     }
 }
 public static string  section_Get_Value_String(this FileBasedConfig config, string section, string name)
 {
     if (config.notNull())
     {
         return(config.GetString(section, null, name));
     }
     return(null);
 }
 public static string        file_Path(this FileBasedConfig fileBasedConfig)
 {
     if (fileBasedConfig.notNull())
     {
         return(fileBasedConfig.GetFile());
     }
     return(null);
 }
 public static List <string> section_Names(this FileBasedConfig config, string section)
 {
     if (config.notNull())
     {
         return(config.GetNames(section).toList());
     }
     return(new List <string>());
 }
 public static FileBasedConfig  section_Set_Value_String(this FileBasedConfig config, string section, string name, string value)
 {
     if (config.notNull())
     {
         config.SetString(section, null, name, value);
         config.Save();
     }
     return(config);
 }
Exemple #11
0
 public MockSystemReader()
 {
     init(Constants.OS_USER_NAME_KEY);
     init(Constants.GIT_AUTHOR_NAME_KEY);
     init(Constants.GIT_AUTHOR_EMAIL_KEY);
     init(Constants.GIT_COMMITTER_NAME_KEY);
     init(Constants.GIT_COMMITTER_EMAIL_KEY);
     userGitConfig = new FileBasedConfig(null);
 }
Exemple #12
0
 public MockSystemReader()
 {
     init(Constants.OS_USER_NAME_KEY);
     init(Constants.GIT_AUTHOR_NAME_KEY);
     init(Constants.GIT_AUTHOR_EMAIL_KEY);
     init(Constants.GIT_COMMITTER_NAME_KEY);
     init(Constants.GIT_COMMITTER_EMAIL_KEY);
     userGitConfig   = new MockFileBasedConfig(null);
     operatingSystem = SystemReader.getInstance().getOperatingSystem();
 }
Exemple #13
0
 public MockSystemReader()
 {
     Init(Constants.OS_USER_NAME_KEY);
     Init(Constants.GIT_AUTHOR_NAME_KEY);
     Init(Constants.GIT_AUTHOR_EMAIL_KEY);
     Init(Constants.GIT_COMMITTER_NAME_KEY);
     Init(Constants.GIT_COMMITTER_EMAIL_KEY);
     userGitConfig   = new MockSystemReader.MockConfig(this, null, null);
     systemGitConfig = new MockSystemReader.MockConfig(this, null, null);
 }
        public virtual void RepositoryWithSubmodule()
        {
            WriteTrashFile("file.txt", "content");
            Git git = Git.Wrap(db);

            git.Add().AddFilepattern("file.txt").Call();
            git.Commit().SetMessage("create file").Call();
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_96(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);
            string url = "git://server/repo.git";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            modulesConfig.Save();
            Repository subRepo = Git.CloneRepository().SetURI(db.Directory.ToURI().ToString()
                                                              ).SetDirectory(new FilePath(db.WorkTree, path)).Call().GetRepository();

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

            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUrl());
            NUnit.Framework.Assert.AreEqual(url, generator.GetModulesUrl());
            SubmoduleSyncCommand         command = new SubmoduleSyncCommand(db);
            IDictionary <string, string> synced  = command.Call();

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

            NUnit.Framework.Assert.AreEqual(path, module.Key);
            NUnit.Framework.Assert.AreEqual(url, module.Value);
            generator = SubmoduleWalk.ForIndex(db);
            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.AreEqual(url, generator.GetConfigUrl());
            Repository subModRepository = generator.GetRepository();

            AddRepoToClose(subModRepository);
            StoredConfig submoduleConfig = subModRepository.GetConfig();

            NUnit.Framework.Assert.AreEqual(url, submoduleConfig.GetString(ConfigConstants.CONFIG_REMOTE_SECTION
                                                                           , Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
        }
 public MockSystemReader(SystemReader initialReader)
 {
     Init(Constants.OS_USER_NAME_KEY);
     Init(Constants.GIT_AUTHOR_NAME_KEY);
     Init(Constants.GIT_AUTHOR_EMAIL_KEY);
     Init(Constants.GIT_COMMITTER_NAME_KEY);
     Init(Constants.GIT_COMMITTER_EMAIL_KEY);
     _userGitConfig       = new MockConfig(null, null);
     _systemGitConfig     = new MockConfig(null, null);
     _initialSystemReader = initialReader;
 }
Exemple #16
0
 /// <summary>
 /// Load the config for this walk from
 /// <code>.gitmodules</code>
 /// .
 /// <p>
 /// Uses the root tree if
 /// <see cref="SetRootTree(NGit.Treewalk.AbstractTreeIterator)">SetRootTree(NGit.Treewalk.AbstractTreeIterator)
 ///     </see>
 /// was
 /// previously called, otherwise uses the working tree.
 /// <p>
 /// If no submodule config is found, loads an empty config.
 /// </summary>
 /// <returns>this generator</returns>
 /// <exception cref="System.IO.IOException">if an error occurred, or if the repository is bare
 ///     </exception>
 /// <exception cref="NGit.Errors.ConfigInvalidException">NGit.Errors.ConfigInvalidException
 ///     </exception>
 public virtual NGit.Submodule.SubmoduleWalk LoadModulesConfig()
 {
     if (rootTree == null)
     {
         FilePath modulesFile = new FilePath(repository.WorkTree, Constants.DOT_GIT_MODULES
                                             );
         FileBasedConfig config = new FileBasedConfig(modulesFile, repository.FileSystem);
         config.Load();
         modulesConfig = config;
     }
     else
     {
         TreeWalk configWalk = new TreeWalk(repository);
         try
         {
             configWalk.AddTree(rootTree);
             // The root tree may be part of the submodule walk, so we need to revert
             // it after this walk.
             int idx;
             for (idx = 0; !rootTree.First; idx++)
             {
                 rootTree.Back(1);
             }
             try
             {
                 configWalk.Recursive = false;
                 PathFilter filter = PathFilter.Create(Constants.DOT_GIT_MODULES);
                 configWalk.Filter = filter;
                 while (configWalk.Next())
                 {
                     if (filter.IsDone(configWalk))
                     {
                         modulesConfig = new BlobBasedConfig(null, repository, configWalk.GetObjectId(0));
                         return(this);
                     }
                 }
                 modulesConfig = new Config();
             }
             finally
             {
                 if (idx > 0)
                 {
                     rootTree.Next(idx);
                 }
             }
         }
         finally
         {
             configWalk.Release();
         }
     }
     return(this);
 }
Exemple #17
0
 public MockSystemReader(SystemReader initialReader)
 {
     Init(Constants.OS_USER_NAME_KEY);
     Init(Constants.GIT_AUTHOR_NAME_KEY);
     Init(Constants.GIT_AUTHOR_EMAIL_KEY);
     Init(Constants.GIT_COMMITTER_NAME_KEY);
     Init(Constants.GIT_COMMITTER_EMAIL_KEY);
     SetProperty("jgit.fs.debug", false.ToString());             //bug #72646. The value is required in case of Cygwin is installed
     _userGitConfig       = new MockConfig(null, null);
     _systemGitConfig     = new MockConfig(null, null);
     _initialSystemReader = initialReader;
 }
        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
                                                ());
        }
        public virtual void ResolveWorkingDirectoryRelativeUrl()
        {
            string path  = AddSubmoduleToIndex();
            string @base = db.WorkTree.GetAbsolutePath();

            if (FilePath.separatorChar == '\\')
            {
                @base = @base.Replace('\\', '/');
            }
            FileBasedConfig config = ((FileBasedConfig)db.GetConfig());

            config.SetString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME
                             , ConfigConstants.CONFIG_KEY_URL, null);
            config.Save();
            SubmoduleWalk generator = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUrl());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUpdate());
            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);
            string url = "./sub.git";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            string update = "rebase";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_UPDATE, update);
            modulesConfig.Save();
            SubmoduleInitCommand command = new SubmoduleInitCommand(db);
            ICollection <string> modules = command.Call();

            NUnit.Framework.Assert.IsNotNull(modules);
            NUnit.Framework.Assert.AreEqual(1, modules.Count);
            NUnit.Framework.Assert.AreEqual(path, modules.Iterator().Next());
            generator = SubmoduleWalk.ForIndex(db);
            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.AreEqual(@base + "/sub.git", generator.GetConfigUrl());
            NUnit.Framework.Assert.AreEqual(update, generator.GetConfigUpdate());
        }
        public virtual void ResolveTwoLevelHigherRelativeUrl()
        {
            string          path   = AddSubmoduleToIndex();
            string          @base  = "git://server/repo.git";
            FileBasedConfig config = ((FileBasedConfig)db.GetConfig());

            config.SetString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME
                             , ConfigConstants.CONFIG_KEY_URL, @base);
            config.Save();
            SubmoduleWalk generator = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUrl());
            NUnit.Framework.Assert.IsNull(generator.GetConfigUpdate());
            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);
            string url = "../../server2/sub.git";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            string update = "rebase";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_UPDATE, update);
            modulesConfig.Save();
            SubmoduleInitCommand command = new SubmoduleInitCommand(db);
            ICollection <string> modules = command.Call();

            NUnit.Framework.Assert.IsNotNull(modules);
            NUnit.Framework.Assert.AreEqual(1, modules.Count);
            NUnit.Framework.Assert.AreEqual(path, modules.Iterator().Next());
            generator = SubmoduleWalk.ForIndex(db);
            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.AreEqual("git://server2/sub.git", generator.GetConfigUrl()
                                            );
            NUnit.Framework.Assert.AreEqual(update, generator.GetConfigUpdate());
        }
        public virtual void TestlogAllRefUpdates()
        {
            long commitTime = 1154236443000L;
            int  tz         = -4 * 60;

            // check that there are no entries in the reflog and turn off writing
            // reflogs
            NUnit.Framework.Assert.AreEqual(0, db.GetReflogReader(Constants.HEAD).GetReverseEntries
                                                ().Count);
            FileBasedConfig cfg = ((FileBasedConfig)db.GetConfig());

            cfg.SetBoolean("core", null, "logallrefupdates", false);
            cfg.Save();
            // do one commit and check that reflog size is 0: no reflogs should be
            // written
            Commit("A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer
                                                                                          , commitTime, tz));
            commitTime += 60 * 1000;
            NUnit.Framework.Assert.IsTrue(db.GetReflogReader(Constants.HEAD).GetReverseEntries
                                              ().Count == 0, "Reflog for HEAD still contain no entry");
            // set the logAllRefUpdates parameter to true and check it
            cfg.SetBoolean("core", null, "logallrefupdates", true);
            cfg.Save();
            NUnit.Framework.Assert.IsTrue(cfg.Get(CoreConfig.KEY).IsLogAllRefUpdates());
            // do one commit and check that reflog size is increased to 1
            Commit("A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer
                                                                                          , commitTime, tz));
            commitTime += 60 * 1000;
            NUnit.Framework.Assert.IsTrue(db.GetReflogReader(Constants.HEAD).GetReverseEntries
                                              ().Count == 1, "Reflog for HEAD should contain one entry");
            // set the logAllRefUpdates parameter to false and check it
            cfg.SetBoolean("core", null, "logallrefupdates", false);
            cfg.Save();
            NUnit.Framework.Assert.IsFalse(cfg.Get(CoreConfig.KEY).IsLogAllRefUpdates());
            // do one commit and check that reflog size is 2
            Commit("A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer
                                                                                          , commitTime, tz));
            NUnit.Framework.Assert.IsTrue(db.GetReflogReader(Constants.HEAD).GetReverseEntries
                                              ().Count == 2, "Reflog for HEAD should contain two entries");
        }
        public virtual void RepositoryWithSubmodule()
        {
            WriteTrashFile("file.txt", "content");
            Git git = Git.Wrap(db);

            git.Add().AddFilepattern("file.txt").Call();
            RevCommit      commit = git.Commit().SetMessage("create file").Call();
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_94(commit, path));
            editor.Commit();
            StoredConfig config = ((FileBasedConfig)db.GetConfig());

            config.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.
                             CONFIG_KEY_URL, db.Directory.ToURI().ToString());
            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.Save();
            SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db);
            ICollection <string>   updated = command.Call();

            NUnit.Framework.Assert.IsNotNull(updated);
            NUnit.Framework.Assert.AreEqual(1, updated.Count);
            NUnit.Framework.Assert.AreEqual(path, updated.Iterator().Next());
            SubmoduleWalk generator = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(generator.Next());
            Repository subRepo = generator.GetRepository();

            AddRepoToClose(subRepo);
            NUnit.Framework.Assert.IsNotNull(subRepo);
            NUnit.Framework.Assert.AreEqual(commit, subRepo.Resolve(Constants.HEAD));
        }
Exemple #23
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));
        }
        public virtual void TestCloneWithAutoSetupRebase()
        {
            FilePath     directory = CreateTempDirectory("testCloneRepository1");
            CloneCommand command   = Git.CloneRepository();

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

            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsFalse(git2.GetRepository().GetConfig().GetBoolean(ConfigConstants
                                                                                       .CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_REBASE, false));
            FileBasedConfig userConfig = SystemReader.GetInstance().OpenUserConfig(null, git.
                                                                                   GetRepository().FileSystem);

            userConfig.SetString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants
                                 .CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_ALWAYS);
            userConfig.Save();
            directory = CreateTempDirectory("testCloneRepository2");
            command   = Git.CloneRepository();
            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            git2 = command.Call();
            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsTrue(git2.GetRepository().GetConfig().GetBoolean(ConfigConstants
                                                                                      .CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_REBASE, false));
            userConfig.SetString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants
                                 .CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_REMOTE);
            userConfig.Save();
            directory = CreateTempDirectory("testCloneRepository2");
            command   = Git.CloneRepository();
            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            git2 = command.Call();
            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsTrue(git2.GetRepository().GetConfig().GetBoolean(ConfigConstants
                                                                                      .CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_REBASE, false));
        }
        /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
        public override Repository Call()
        {
            CheckCallable();
            if (path == null || path.Length == 0)
            {
                throw new ArgumentException(JGitText.Get().pathNotConfigured);
            }
            if (uri == null || uri.Length == 0)
            {
                throw new ArgumentException(JGitText.Get().uriNotConfigured);
            }
            try
            {
                if (SubmoduleExists())
                {
                    throw new JGitInternalException(MessageFormat.Format(JGitText.Get().submoduleExists
                                                                         , path));
                }
            }
            catch (IOException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            string resolvedUri;

            try
            {
                resolvedUri = SubmoduleWalk.GetSubmoduleRemoteUrl(repo, uri);
            }
            catch (IOException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            // Clone submodule repository
            FilePath     moduleDirectory = SubmoduleWalk.GetSubmoduleDirectory(repo, path);
            CloneCommand clone           = Git.CloneRepository();

            Configure(clone);
            clone.SetDirectory(moduleDirectory);
            clone.SetURI(resolvedUri);
            if (monitor != null)
            {
                clone.SetProgressMonitor(monitor);
            }
            Repository subRepo = clone.Call().GetRepository();
            // Save submodule URL to parent repository's config
            StoredConfig config = repo.GetConfig();

            config.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.
                             CONFIG_KEY_URL, resolvedUri);
            try
            {
                config.Save();
            }
            catch (IOException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            // Save path and URL to parent repository's .gitmodules file
            FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(repo.WorkTree, Constants
                                                                             .DOT_GIT_MODULES), repo.FileSystem);

            try
            {
                modulesConfig.Load();
                modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                        .CONFIG_KEY_PATH, path);
                modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                        .CONFIG_KEY_URL, uri);
                modulesConfig.Save();
            }
            catch (IOException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            catch (ConfigInvalidException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            AddCommand add = new AddCommand(repo);

            // Add .gitmodules file to parent repository's index
            add.AddFilepattern(Constants.DOT_GIT_MODULES);
            // Add submodule directory to parent repository's index
            add.AddFilepattern(path);
            try
            {
                add.Call();
            }
            catch (NoFilepatternException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            return(subRepo);
        }
 public static string        file_Contents(this FileBasedConfig fileBasedConfig)
 {
     return(fileBasedConfig.file_Path().fileContents());
 }