Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
 /// <exception cref="System.IO.IOException"></exception>
 private void LoadUserConfig()
 {
     try
     {
         userConfig.Load();
     }
     catch (ConfigInvalidException e1)
     {
         IOException e2 = new IOException(MessageFormat.Format(JGitText.Get().userConfigFileInvalid
                                                               , userConfig.GetFile().GetAbsolutePath(), e1));
         Sharpen.Extensions.InitCause(e2, e1);
         throw e2;
     }
 }