Example #1
0
        public virtual void Test006_ReadUglyConfig()
        {
            FilePath        cfg       = new FilePath(db.Directory, "config");
            FileBasedConfig c         = new FileBasedConfig(cfg, db.FileSystem);
            string          configStr = "  [core];comment\n\tfilemode = yes\n" + "[user]\n" + "  email = A U Thor <*****@*****.**> # Just an example...\n"
                                        + " name = \"A  Thor \\\\ \\\"\\t \"\n" + "    defaultCheckInComment = a many line\\n\\\ncomment\\n\\\n"
                                        + " to test\n";

            Write(cfg, configStr);
            c.Load();
            NUnit.Framework.Assert.AreEqual("yes", c.GetString("core", null, "filemode"));
            NUnit.Framework.Assert.AreEqual("A U Thor <*****@*****.**>", c.GetString("user"
                                                                                       , null, "email"));
            NUnit.Framework.Assert.AreEqual("A  Thor \\ \"\t ", c.GetString("user", null, "name"
                                                                            ));
            NUnit.Framework.Assert.AreEqual("a many line\ncomment\n to test", c.GetString("user"
                                                                                          , null, "defaultCheckInComment"));
            c.Save();
            FileReader fr = new FileReader(cfg);

            char[] cbuf = new char[configStr.Length];
            fr.Read(cbuf);
            fr.Close();
            NUnit.Framework.Assert.AreEqual(configStr, new string(cbuf));
        }
Example #2
0
		public virtual void TestSystemEncoding()
		{
			FilePath file = CreateFile(Sharpen.Runtime.GetBytesForString(CONTENT1));
			FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
			config.Load();
			NUnit.Framework.Assert.AreEqual(ALICE, config.GetString(USER, null, NAME));
			config.SetString(USER, null, NAME, BOB);
			config.Save();
			Assert.AssertArrayEquals(Sharpen.Runtime.GetBytesForString(CONTENT2), IOUtil.ReadFully
				(file));
		}
Example #3
0
        public virtual void TestUTF8withoutBOM()
        {
            FilePath        file   = CreateFile(Sharpen.Runtime.GetBytesForString(CONTENT1, "UTF-8"));
            FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);

            config.Load();
            NUnit.Framework.Assert.AreEqual(ALICE, config.GetString(USER, null, NAME));
            config.SetString(USER, null, NAME, BOB);
            config.Save();
            Assert.AssertArrayEquals(Sharpen.Runtime.GetBytesForString(CONTENT2), IOUtil.ReadFully
                                         (file));
        }
Example #4
0
        public virtual void TestLeadingWhitespaces()
        {
            ByteArrayOutputStream bos1 = new ByteArrayOutputStream();

            bos1.Write(Sharpen.Runtime.GetBytesForString(" \n\t"));
            bos1.Write(Sharpen.Runtime.GetBytesForString(CONTENT1));
            FilePath        file   = CreateFile(bos1.ToByteArray());
            FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);

            config.Load();
            NUnit.Framework.Assert.AreEqual(ALICE, config.GetString(USER, null, NAME));
            config.SetString(USER, null, NAME, BOB);
            config.Save();
            ByteArrayOutputStream bos2 = new ByteArrayOutputStream();

            bos2.Write(Sharpen.Runtime.GetBytesForString(" \n\t"));
            bos2.Write(Sharpen.Runtime.GetBytesForString(CONTENT2));
            Assert.AssertArrayEquals(bos2.ToByteArray(), IOUtil.ReadFully(file));
        }
Example #5
0
        public virtual void TestUTF8withBOM()
        {
            ByteArrayOutputStream bos1 = new ByteArrayOutputStream();

            bos1.Write(unchecked ((int)(0xEF)));
            bos1.Write(unchecked ((int)(0xBB)));
            bos1.Write(unchecked ((int)(0xBF)));
            bos1.Write(Sharpen.Runtime.GetBytesForString(CONTENT1, "UTF-8"));
            FilePath        file   = CreateFile(bos1.ToByteArray());
            FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);

            config.Load();
            NUnit.Framework.Assert.AreEqual(ALICE, config.GetString(USER, null, NAME));
            config.SetString(USER, null, NAME, BOB);
            config.Save();
            ByteArrayOutputStream bos2 = new ByteArrayOutputStream();

            bos2.Write(unchecked ((int)(0xEF)));
            bos2.Write(unchecked ((int)(0xBB)));
            bos2.Write(unchecked ((int)(0xBF)));
            bos2.Write(Sharpen.Runtime.GetBytesForString(CONTENT2, "UTF-8"));
            Assert.AssertArrayEquals(bos2.ToByteArray(), IOUtil.ReadFully(file));
        }
        /// <summary>
        /// グローバル設定ファイル読み込み
        /// </summary>
        public GrobalConfigEntity LoadGrobalConfig()
        {
            FilePath gitconfig = new FilePath(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".gitconfig");

            if (!gitconfig.Exists())
            {
                return null;
            }
            FileBasedConfig config = new FileBasedConfig(gitconfig, FS.Detect());

            config.Load();
/*
            string text = config.ToText();

            foreach (string section in config.GetSections())
            {
                Console.Out.WriteLine("section = {0}", section);

                if (config.GetSubsections(section).Count > 0)
                {
                    foreach (string subsection in config.GetSubsections(section))
                    {
                        Console.Out.WriteLine(" subsection = {0}", subsection);

                        foreach (string name in config.GetNames(section, subsection))
                        {
                            Console.Out.WriteLine("  name = {0} / value = {1}", name, config.GetString(section, subsection, name));
                        }
                    }
                }
                else
                {
                    foreach (string name in config.GetNames(section))
                    {
                        Console.Out.WriteLine("  name = {0} / value = {1}", name, config.GetString(section, null, name));
                    }
                }
            }
*/
            GrobalConfigEntity result = new GrobalConfigEntity();

            result.EMail = config.GetString("user", null, "email");
            result.Name = config.GetString("user", null, "name");

            if (result.EMail == null || result.Name == null)
            {
                return null;
            }
            return result;
        }
Example #7
0
 public virtual void Test006_ReadUglyConfig()
 {
     FilePath cfg = new FilePath(db.Directory, Constants.CONFIG);
     FileBasedConfig c = new FileBasedConfig(cfg, db.FileSystem);
     string configStr = "  [core];comment\n\tfilemode = yes\n" + "[user]\n" + "  email = A U Thor <*****@*****.**> # Just an example...\n"
          + " name = \"A  Thor \\\\ \\\"\\t \"\n" + "    defaultCheckInComment = a many line\\n\\\ncomment\\n\\\n"
          + " to test\n";
     Write(cfg, configStr);
     c.Load();
     NUnit.Framework.Assert.AreEqual("yes", c.GetString("core", null, "filemode"));
     NUnit.Framework.Assert.AreEqual("A U Thor <*****@*****.**>", c.GetString("user"
         , null, "email"));
     NUnit.Framework.Assert.AreEqual("A  Thor \\ \"\t ", c.GetString("user", null, "name"
         ));
     NUnit.Framework.Assert.AreEqual("a many line\ncomment\n to test", c.GetString("user"
         , null, "defaultCheckInComment"));
     c.Save();
     FileReader fr = new FileReader(cfg);
     char[] cbuf = new char[configStr.Length];
     fr.Read(cbuf);
     fr.Close();
     NUnit.Framework.Assert.AreEqual(configStr, new string(cbuf));
 }
Example #8
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));
 }
Example #9
0
		public virtual void TestLeadingWhitespaces()
		{
			ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
			bos1.Write(Sharpen.Runtime.GetBytesForString(" \n\t"));
			bos1.Write(Sharpen.Runtime.GetBytesForString(CONTENT1));
			FilePath file = CreateFile(bos1.ToByteArray());
			FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
			config.Load();
			NUnit.Framework.Assert.AreEqual(ALICE, config.GetString(USER, null, NAME));
			config.SetString(USER, null, NAME, BOB);
			config.Save();
			ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
			bos2.Write(Sharpen.Runtime.GetBytesForString(" \n\t"));
			bos2.Write(Sharpen.Runtime.GetBytesForString(CONTENT2));
			Assert.AssertArrayEquals(bos2.ToByteArray(), IOUtil.ReadFully(file));
		}
Example #10
0
		public virtual void TestUTF8withBOM()
		{
			ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
			bos1.Write(unchecked((int)(0xEF)));
			bos1.Write(unchecked((int)(0xBB)));
			bos1.Write(unchecked((int)(0xBF)));
			bos1.Write(Sharpen.Runtime.GetBytesForString(CONTENT1, "UTF-8"));
			FilePath file = CreateFile(bos1.ToByteArray());
			FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
			config.Load();
			NUnit.Framework.Assert.AreEqual(ALICE, config.GetString(USER, null, NAME));
			config.SetString(USER, null, NAME, BOB);
			config.Save();
			ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
			bos2.Write(unchecked((int)(0xEF)));
			bos2.Write(unchecked((int)(0xBB)));
			bos2.Write(unchecked((int)(0xBF)));
			bos2.Write(Sharpen.Runtime.GetBytesForString(CONTENT2, "UTF-8"));
			Assert.AssertArrayEquals(bos2.ToByteArray(), IOUtil.ReadFully(file));
		}