@@ -41,15 +41,21 @@ VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg)
4141
4242/*
4343 * call-seq:
44- * Config.new(path) -> new_config
44+ * Config.new([ path] ) -> config
4545 *
46- * Open the file specified in +path+ as a +Rugged::Config+ file.
47- * If +path+ cannot be found, or the file is an invalid Git config,
48- * an exception will be raised.
46+ * Create a new config object.
47+ *
48+ * If +path+ is specified, the file at this path will be used as the backing
49+ * config store. +path+ can also be an array of file paths to be used.
50+ *
51+ * If +path+ is not specified, an empty config object will be returned.
4952 */
50- static VALUE rb_git_config_new (VALUE klass , VALUE rb_path )
53+ static VALUE rb_git_config_new (int argc , VALUE * argv , VALUE klass )
5154{
52- git_config * config = NULL ;
55+ git_config * config ;
56+ VALUE rb_path ;
57+
58+ rb_scan_args (argc , argv , "01" , & rb_path );
5359
5460 if (TYPE (rb_path ) == T_ARRAY ) {
5561 int error , i ;
@@ -71,8 +77,11 @@ static VALUE rb_git_config_new(VALUE klass, VALUE rb_path)
7177 rugged_exception_check (
7278 git_config_open_ondisk (& config , StringValueCStr (rb_path ))
7379 );
80+ } else if (NIL_P (rb_path )) {
81+ rugged_exception_check (git_config_new (& config ));
7482 } else {
75- rb_raise (rb_eTypeError , "Expecting a filename or an array of filenames" );
83+ rb_raise (rb_eTypeError , "wrong argument type %s (expected an Array, String, or nil)" ,
84+ rb_obj_classname (rb_path ));
7685 }
7786
7887 return rugged_config_new (klass , Qnil , config );
@@ -381,7 +390,7 @@ void Init_rugged_config(void)
381390 * Config
382391 */
383392 rb_cRuggedConfig = rb_define_class_under (rb_mRugged , "Config" , rb_cObject );
384- rb_define_singleton_method (rb_cRuggedConfig , "new" , rb_git_config_new , 1 );
393+ rb_define_singleton_method (rb_cRuggedConfig , "new" , rb_git_config_new , - 1 );
385394
386395 rb_define_singleton_method (rb_cRuggedConfig , "global" , rb_git_config_open_default , 0 );
387396 rb_define_singleton_method (rb_cRuggedConfig , "open_global" , rb_git_config_open_default , 0 );
0 commit comments