Skip to content

Commit 2870fce

Browse files
authored
Merge pull request #769 from marcandre/pathname
Support Ruby's convention for pathnames and Pathname lib
2 parents 419b2e4 + dbf96e3 commit 2870fce

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

ext/rugged/rugged_blob.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static VALUE rb_git_blob_from_workdir(VALUE self, VALUE rb_repo, VALUE rb_path)
165165
git_oid oid;
166166
git_repository *repo;
167167

168-
Check_Type(rb_path, T_STRING);
168+
FilePathValue(rb_path);
169169
rugged_check_repo(rb_repo);
170170

171171
Data_Get_Struct(rb_repo, git_repository, repo);
@@ -193,7 +193,7 @@ static VALUE rb_git_blob_from_disk(VALUE self, VALUE rb_repo, VALUE rb_path)
193193
git_oid oid;
194194
git_repository *repo;
195195

196-
Check_Type(rb_path, T_STRING);
196+
FilePathValue(rb_path);
197197
rugged_check_repo(rb_repo);
198198

199199
Data_Get_Struct(rb_repo, git_repository, repo);
@@ -254,7 +254,7 @@ static VALUE rb_git_blob_from_io(int argc, VALUE *argv, VALUE klass)
254254
Data_Get_Struct(rb_repo, git_repository, repo);
255255

256256
if (!NIL_P(rb_hint_path)) {
257-
Check_Type(rb_hint_path, T_STRING);
257+
FilePathValue(rb_hint_path);
258258
hint_path = StringValueCStr(rb_hint_path);
259259
}
260260

ext/rugged/rugged_repo.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
182182

183183
int error = 0;
184184

185-
Check_Type(rb_path, T_STRING);
185+
FilePathValue(rb_path);
186186
path = StringValueCStr(rb_path);
187187

188188
if (rb_obj_is_kind_of(rb_backend, rb_cRuggedBackend) == Qfalse) {
@@ -291,7 +291,7 @@ static VALUE rb_git_repo_open_bare(int argc, VALUE *argv, VALUE klass)
291291
}
292292

293293
if (!repo) {
294-
Check_Type(rb_path, T_STRING);
294+
FilePathValue(rb_path);
295295

296296
error = git_repository_open_bare(&repo, StringValueCStr(rb_path));
297297
rugged_exception_check(error);
@@ -335,7 +335,7 @@ static VALUE rb_git_repo_new(int argc, VALUE *argv, VALUE klass)
335335
VALUE rb_path, rb_options;
336336

337337
rb_scan_args(argc, argv, "10:", &rb_path, &rb_options);
338-
Check_Type(rb_path, T_STRING);
338+
FilePathValue(rb_path);
339339

340340
error = git_repository_open(&repo, StringValueCStr(rb_path));
341341
rugged_exception_check(error);
@@ -377,7 +377,7 @@ static VALUE rb_git_repo_init_at(int argc, VALUE *argv, VALUE klass)
377377
int error;
378378

379379
rb_scan_args(argc, argv, "11:", &rb_path, &rb_is_bare, &rb_options);
380-
Check_Type(rb_path, T_STRING);
380+
FilePathValue(rb_path);
381381

382382
if (!NIL_P(rb_options)) {
383383
/* Check for `:backend` */
@@ -474,7 +474,7 @@ static VALUE rb_git_repo_clone_at(int argc, VALUE *argv, VALUE klass)
474474

475475
rb_scan_args(argc, argv, "21", &url, &local_path, &rb_options_hash);
476476
Check_Type(url, T_STRING);
477-
Check_Type(local_path, T_STRING);
477+
FilePathValue(local_path);
478478

479479
parse_clone_options(&options, rb_options_hash, &remote_payload);
480480

@@ -1180,7 +1180,7 @@ static VALUE rb_git_repo_hashfile(VALUE self, VALUE rb_path, VALUE rb_type)
11801180
int error;
11811181
git_oid oid;
11821182

1183-
Check_Type(rb_path, T_STRING);
1183+
FilePathValue(rb_path);
11841184

11851185
error = git_odb_hashfile(&oid,
11861186
StringValueCStr(rb_path),
@@ -1455,7 +1455,7 @@ static VALUE rb_git_repo_discover(int argc, VALUE *argv, VALUE klass)
14551455
across_fs = rugged_parse_bool(rb_across_fs);
14561456
}
14571457

1458-
Check_Type(rb_path, T_STRING);
1458+
FilePathValue(rb_path);
14591459

14601460
error = git_repository_discover(
14611461
&repository_path,
@@ -1518,7 +1518,7 @@ static VALUE rb_git_repo_file_status(VALUE self, VALUE rb_path)
15181518
git_repository *repo;
15191519

15201520
Data_Get_Struct(self, git_repository, repo);
1521-
Check_Type(rb_path, T_STRING);
1521+
FilePathValue(rb_path);
15221522
error = git_status_file(&flags, repo, StringValueCStr(rb_path));
15231523
rugged_exception_check(error);
15241524

@@ -2365,7 +2365,7 @@ static VALUE rb_git_repo_attributes(int argc, VALUE *argv, VALUE self)
23652365
rb_scan_args(argc, argv, "12", &rb_path, &rb_names, &rb_options);
23662366

23672367
Data_Get_Struct(self, git_repository, repo);
2368-
Check_Type(rb_path, T_STRING);
2368+
FilePathValue(rb_path);
23692369

23702370
if (!NIL_P(rb_options)) {
23712371
Check_Type(rb_options, T_FIXNUM);

test/repo_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,22 @@ def test_init_non_bare_default
503503
repo.close
504504
end
505505
end
506+
507+
def test_init_with_pathname
508+
require 'pathname'
509+
repo = Rugged::Repository.init_at(Pathname(@tmppath))
510+
begin
511+
refute repo.bare?
512+
ensure
513+
repo.close
514+
end
515+
end
516+
517+
def test_init_with_wrong_argument
518+
assert_raises(TypeError) do
519+
Rugged::Repository.init_at(@tmppath.to_sym)
520+
end
521+
end
506522
end
507523

508524
class RepositoryCloneTest < Rugged::TestCase

0 commit comments

Comments
 (0)