@@ -41,15 +41,21 @@ VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg)
41
41
42
42
/*
43
43
* call-seq:
44
- * Config.new(path) -> new_config
44
+ * Config.new([ path] ) -> config
45
45
*
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.
49
52
*/
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 )
51
54
{
52
- git_config * config = NULL ;
55
+ git_config * config ;
56
+ VALUE rb_path ;
57
+
58
+ rb_scan_args (argc , argv , "01" , & rb_path );
53
59
54
60
if (TYPE (rb_path ) == T_ARRAY ) {
55
61
int error , i ;
@@ -71,8 +77,11 @@ static VALUE rb_git_config_new(VALUE klass, VALUE rb_path)
71
77
rugged_exception_check (
72
78
git_config_open_ondisk (& config , StringValueCStr (rb_path ))
73
79
);
80
+ } else if (NIL_P (rb_path )) {
81
+ rugged_exception_check (git_config_new (& config ));
74
82
} 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 ));
76
85
}
77
86
78
87
return rugged_config_new (klass , Qnil , config );
@@ -381,7 +390,7 @@ void Init_rugged_config(void)
381
390
* Config
382
391
*/
383
392
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 );
385
394
386
395
rb_define_singleton_method (rb_cRuggedConfig , "global" , rb_git_config_open_default , 0 );
387
396
rb_define_singleton_method (rb_cRuggedConfig , "open_global" , rb_git_config_open_default , 0 );
0 commit comments