Esempio n. 1
0
        private ConfigurationSafeHandle RetrieveConfigurationHandle(ConfigurationLevel level, bool throwIfStoreHasNotBeenFound)
        {
            ConfigurationSafeHandle handle = null;

            if (configHandle != null)
            {
                handle = Proxy.git_config_open_level(configHandle, level);
            }

            if (handle == null && throwIfStoreHasNotBeenFound)
            {
                throw new LibGit2SharpException(
                          string.Format(CultureInfo.InvariantCulture, "No {0} configuration file has been found.",
                                        Enum.GetName(typeof(ConfigurationLevel), level)));
            }

            return(handle);
        }
Esempio n. 2
0
        /// <summary>
        ///   Get a configuration value for a key. Keys are in the form 'section.name'.
        ///   <para>
        ///     For example in  order to get the value for this in a .git\config file:
        ///
        ///     <code>
        ///     [core]
        ///     bare = true
        ///     </code>
        ///
        ///     You would call:
        ///
        ///     <code>
        ///     bool isBare = repo.Config.Get&lt;bool&gt;("core.bare", false);
        ///     </code>
        ///   </para>
        /// </summary>
        /// <typeparam name = "T">The configuration value type</typeparam>
        /// <param name = "key">The key</param>
        /// <param name = "defaultValue">The default value</param>
        /// <returns>The configuration value, or <c>defaultValue</c> if not set</returns>
        public T Get <T>(string key, T defaultValue)
        {
            Ensure.ArgumentNotNullOrEmptyString(key, "key");

            if (!configurationTypedRetriever.ContainsKey(typeof(T)))
            {
                throw new ArgumentException(string.Format("Generic Argument of type '{0}' is not supported.", typeof(T).FullName));
            }

            ConfigurationSafeHandle handle = (LocalHandle ?? globalHandle) ?? systemHandle;

            if (handle == null)
            {
                throw new LibGit2Exception("Could not find a local, global or system level configuration.");
            }

            return((T)configurationTypedRetriever[typeof(T)](key, defaultValue, handle));
        }
Esempio n. 3
0
        private void Init(Repository repository)
        {
            configHandle = Proxy.git_config_new();

            if (repository != null)
            {
                //TODO: push back this logic into libgit2.
                // As stated by @carlosmn "having a helper function to load the defaults and then allowing you
                // to modify it before giving it to git_repository_open_ext() would be a good addition, I think."
                //  -- Agreed :)
                string repoConfigLocation = Path.Combine(repository.Info.Path, "config");
                Proxy.git_config_add_file_ondisk(configHandle, repoConfigLocation, ConfigurationLevel.Local);

                Proxy.git_repository_set_config(repository.Handle, configHandle);
            }
            else if (repoConfigPath != null)
            {
                Proxy.git_config_add_file_ondisk(configHandle, repoConfigPath, ConfigurationLevel.Local);
            }

            if (globalConfigPath != null)
            {
                Proxy.git_config_add_file_ondisk(configHandle, globalConfigPath, ConfigurationLevel.Global);
            }

            if (xdgConfigPath != null)
            {
                Proxy.git_config_add_file_ondisk(configHandle, xdgConfigPath, ConfigurationLevel.Xdg);
            }

            if (systemConfigPath != null)
            {
                Proxy.git_config_add_file_ondisk(configHandle, systemConfigPath, ConfigurationLevel.System);
            }

            if (programDataConfigPath != null)
            {
                Proxy.git_config_add_file_ondisk(configHandle, programDataConfigPath, ConfigurationLevel.ProgramData);
            }
        }
Esempio n. 4
0
        private ConfigurationSafeHandle RetrieveConfigurationHandle(ConfigurationLevel level, bool throwIfStoreHasNotBeenFound, ConfigurationSafeHandle fromHandle)
        {
            ConfigurationSafeHandle handle = null;

            if (fromHandle != null)
            {
                handle = Proxy.git_config_open_level(fromHandle, level);
            }

            if (handle == null && throwIfStoreHasNotBeenFound)
            {
                throw new LibGit2SharpException("No {0} configuration file has been found.",
                                                Enum.GetName(typeof(ConfigurationLevel), level));
            }

            return(handle);
        }