Exemplo n.º 1
0
 /// <summary>Create a repository using the local file system.</summary>
 /// <remarks>Create a repository using the local file system.</remarks>
 /// <param name="options">description of the repository's important paths.</param>
 /// <exception cref="System.IO.IOException">
 /// the user configuration file or repository configuration file
 /// cannot be accessed.
 /// </exception>
 protected internal FileRepository(BaseRepositoryBuilder options) : base(options)
 {
     systemConfig = SystemReader.GetInstance().OpenSystemConfig(null, FileSystem);
     userConfig   = SystemReader.GetInstance().OpenUserConfig(systemConfig, FileSystem);
     repoConfig   = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, "config"
                                                                       ), FileSystem);
     //
     //
     LoadSystemConfig();
     LoadUserConfig();
     LoadRepoConfig();
     repoConfig.AddChangeListener(new _ConfigChangedListener_168(this));
     refs           = new RefDirectory(this);
     objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
                                          .GetAlternateObjectDirectories(), FileSystem);
     //
     //
     //
     if (objectDatabase.Exists())
     {
         string repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetString(ConfigConstants
                                                                                   .CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION);
         if (!"0".Equals(repositoryFormatVersion))
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
                                                        , repositoryFormatVersion));
         }
     }
 }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
 /// <summary>Create a repository using the local file system.</summary>
 /// <remarks>Create a repository using the local file system.</remarks>
 /// <param name="options">description of the repository's important paths.</param>
 /// <exception cref="System.IO.IOException">
 /// the user configuration file or repository configuration file
 /// cannot be accessed.
 /// </exception>
 protected internal FileRepository(BaseRepositoryBuilder options) : base(options)
 {
     systemConfig = SystemReader.GetInstance().OpenSystemConfig(null, FileSystem);
     userConfig   = SystemReader.GetInstance().OpenUserConfig(systemConfig, FileSystem);
     repoConfig   = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, Constants
                                                                       .CONFIG), FileSystem);
     LoadSystemConfig();
     LoadUserConfig();
     LoadRepoConfig();
     repoConfig.AddChangeListener(new _ConfigChangedListener_171(this));
     refs           = new RefDirectory(this);
     objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
                                          .GetAlternateObjectDirectories(), FileSystem);
     //
     //
     //
     if (objectDatabase.Exists())
     {
         long repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetLong(ConfigConstants
                                                                               .CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
         if (repositoryFormatVersion > 0)
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
                                                        , Sharpen.Extensions.ValueOf(repositoryFormatVersion)));
         }
     }
     if (!IsBare)
     {
         snapshot = FileSnapshot.Save(GetIndexFile());
     }
 }
Exemplo n.º 4
0
		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());
		}
Exemplo n.º 5
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Errors.ConfigInvalidException"></exception>
        private FileBasedConfig ConfigFor(FilePath gitDir)
        {
            FilePath        configPath = new FilePath(gitDir, Constants.CONFIG);
            FileBasedConfig cfg        = new FileBasedConfig(configPath, FS.DETECTED);

            cfg.Load();
            return(cfg);
        }
Exemplo n.º 6
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Errors.ConfigInvalidException"></exception>
        private void SetBare(FilePath gitDir, bool bare)
        {
            FileBasedConfig cfg = ConfigFor(gitDir);

            cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE
                           , bare);
            cfg.Save();
        }
Exemplo n.º 7
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Errors.ConfigInvalidException"></exception>
        private void SetWorkTree(FilePath gitDir, FilePath workTree)
        {
            string          path = workTree.GetAbsolutePath();
            FileBasedConfig cfg  = ConfigFor(gitDir);

            cfg.SetString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_WORKTREE
                          , path);
            cfg.Save();
        }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
0
        public virtual void EmptyRepositoryFormatVersion()
        {
            FileRepository  r      = CreateWorkRepository();
            FileBasedConfig config = ((FileBasedConfig)r.GetConfig());

            config.SetString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION
                             , string.Empty);
            config.Save();
            new FileRepository(r.Directory);
        }
Exemplo n.º 10
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));
		}
Exemplo n.º 11
0
        /// <summary>
        /// Create a new Git repository initializing the necessary files and
        /// directories.
        /// </summary>
        /// <remarks>
        /// Create a new Git repository initializing the necessary files and
        /// directories.
        /// </remarks>
        /// <param name="bare">if true, a bare repository is created.</param>
        /// <exception cref="System.IO.IOException">in case of IO problem</exception>
        public override void Create(bool bare)
        {
            FileBasedConfig cfg = ((FileBasedConfig)GetConfig());

            if (cfg.GetFile().Exists())
            {
                throw new InvalidOperationException(MessageFormat.Format(JGitText.Get().repositoryAlreadyExists
                                                                         , Directory));
            }
            FileUtils.Mkdirs(Directory, true);
            refs.Create();
            objectDatabase.Create();
            FileUtils.Mkdir(new FilePath(Directory, "branches"));
            FileUtils.Mkdir(new FilePath(Directory, "hooks"));
            RefUpdate head = UpdateRef(Constants.HEAD);

            head.DisableRefLog();
            head.Link(Constants.R_HEADS + Constants.MASTER);
            bool fileMode;

            if (FileSystem.SupportsExecute())
            {
                FilePath tmp = FilePath.CreateTempFile("try", "execute", Directory);
                FileSystem.SetExecute(tmp, true);
                bool on = FileSystem.CanExecute(tmp);
                FileSystem.SetExecute(tmp, false);
                bool off = FileSystem.CanExecute(tmp);
                FileUtils.Delete(tmp);
                fileMode = on && !off;
            }
            else
            {
                fileMode = false;
            }
            cfg.SetInt(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION
                       , 0);
            cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE
                           , fileMode);
            if (bare)
            {
                cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE
                               , true);
            }
            cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES
                           , !bare);
            if (SystemReader.GetInstance().IsMacOS())
            {
                // Java has no other way
                cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_PRECOMPOSEUNICODE
                               , true);
            }
            cfg.Save();
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
0
        public virtual void InvalidRepositoryFormatVersion()
        {
            FileRepository  r      = CreateWorkRepository();
            FileBasedConfig config = ((FileBasedConfig)r.GetConfig());

            config.SetString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION
                             , "notanumber");
            config.Save();
            try
            {
                new FileRepository(r.Directory);
                NUnit.Framework.Assert.Fail("IllegalArgumentException not thrown");
            }
            catch (ArgumentException e)
            {
                NUnit.Framework.Assert.IsNotNull(e.Message);
            }
        }
Exemplo n.º 14
0
		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));
		}
Exemplo n.º 15
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));
        }
Exemplo n.º 16
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));
        }
Exemplo n.º 17
0
        public virtual void Test000_openrepo_default_relative_workdirconfig()
        {
            FilePath repo1Parent = new FilePath(trash.GetParentFile(), "r1");
            FilePath workdir     = new FilePath(trash.GetParentFile(), "rw");

            FileUtils.Mkdir(workdir);
            FileRepository repo1initial = new FileRepository(new FilePath(repo1Parent, Constants
                                                                          .DOT_GIT));

            repo1initial.Create();
            FileBasedConfig cfg = ((FileBasedConfig)repo1initial.GetConfig());

            cfg.SetString("core", null, "worktree", "../../rw");
            cfg.Save();
            repo1initial.Close();
            FilePath       theDir = new FilePath(repo1Parent, Constants.DOT_GIT);
            FileRepository r      = new FileRepositoryBuilder().SetGitDir(theDir).Build();

            AssertEqualsPath(theDir, r.Directory);
            AssertEqualsPath(workdir, r.WorkTree);
            AssertEqualsPath(new FilePath(theDir, "index"), r.GetIndexFile());
            AssertEqualsPath(new FilePath(theDir, "objects"), ((ObjectDirectory)r.ObjectDatabase
                                                               ).GetDirectory());
        }
Exemplo n.º 18
0
 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());
 }
Exemplo n.º 19
0
        /// <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;
        }
Exemplo n.º 20
0
		/// <summary>Reset generator and start new submodule walk</summary>
		/// <returns>this generator</returns>
		public virtual NGit.Submodule.SubmoduleWalk Reset()
		{
			repoConfig = repository.GetConfig();
			modulesConfig = null;
			walk.Reset();
			return this;
		}
Exemplo n.º 21
0
		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));
		}
Exemplo n.º 22
0
		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());
		}
Exemplo n.º 23
0
 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());
 }
Exemplo n.º 24
0
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="NGit.Errors.ConfigInvalidException"></exception>
		private void LoadModulesConfig()
		{
			if (modulesConfig == null)
			{
				FilePath modulesFile = new FilePath(repository.WorkTree, Constants.DOT_GIT_MODULES
					);
				FileBasedConfig config = new FileBasedConfig(modulesFile, repository.FileSystem);
				config.Load();
				modulesConfig = config;
			}
		}
Exemplo n.º 25
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.º 26
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));
		}
Exemplo n.º 27
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;
		}
Exemplo n.º 28
0
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="NGit.Errors.ConfigInvalidException"></exception>
		private FileBasedConfig ConfigFor(FilePath gitDir)
		{
			FilePath configPath = new FilePath(gitDir, Constants.CONFIG);
			FileBasedConfig cfg = new FileBasedConfig(configPath, FS.DETECTED);
			cfg.Load();
			return cfg;
		}
Exemplo n.º 29
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));
 }
Exemplo n.º 30
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));
 }
Exemplo n.º 31
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));
		}
Exemplo n.º 32
0
		/// <summary>Create a repository using the local file system.</summary>
		/// <remarks>Create a repository using the local file system.</remarks>
		/// <param name="options">description of the repository's important paths.</param>
		/// <exception cref="System.IO.IOException">
		/// the user configuration file or repository configuration file
		/// cannot be accessed.
		/// </exception>
		protected internal FileRepository(BaseRepositoryBuilder options) : base(options)
		{
			userConfig = SystemReader.GetInstance().OpenUserConfig(FileSystem);
			repoConfig = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, "config"
				), FileSystem);
			//
			//
			LoadUserConfig();
			LoadRepoConfig();
			((FileBasedConfig)GetConfig()).AddChangeListener(new _ConfigChangedListener_163(this
				));
			refs = new RefDirectory(this);
			objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
				.GetAlternateObjectDirectories(), FileSystem);
			//
			//
			//
			if (objectDatabase.Exists())
			{
				string repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetString(ConfigConstants
					.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION);
				if (!"0".Equals(repositoryFormatVersion))
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
						, repositoryFormatVersion));
				}
			}
		}
Exemplo n.º 33
0
 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);
     }
 }
Exemplo n.º 34
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.º 35
0
 /// <summary>Create a repository using the local file system.</summary>
 /// <remarks>Create a repository using the local file system.</remarks>
 /// <param name="options">description of the repository's important paths.</param>
 /// <exception cref="System.IO.IOException">
 /// the user configuration file or repository configuration file
 /// cannot be accessed.
 /// </exception>
 protected internal FileRepository(BaseRepositoryBuilder options)
     : base(options)
 {
     systemConfig = SystemReader.GetInstance().OpenSystemConfig(null, FileSystem);
     userConfig = SystemReader.GetInstance().OpenUserConfig(systemConfig, FileSystem);
     repoConfig = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, Constants
         .CONFIG), FileSystem);
     LoadSystemConfig();
     LoadUserConfig();
     LoadRepoConfig();
     repoConfig.AddChangeListener(new _ConfigChangedListener_171(this));
     refs = new RefDirectory(this);
     objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
         .GetAlternateObjectDirectories(), FileSystem);
     //
     //
     //
     if (objectDatabase.Exists())
     {
         long repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetLong(ConfigConstants
             .CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
         if (repositoryFormatVersion > 0)
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
                 , Sharpen.Extensions.ValueOf(repositoryFormatVersion)));
         }
     }
     if (!IsBare)
     {
         snapshot = FileSnapshot.Save(GetIndexFile());
     }
 }