From 5e740a4307d29772bacafa4da2cdefa8751ae8cd Mon Sep 17 00:00:00 2001 From: Albert Sun Date: Mon, 24 Mar 2014 14:33:37 -0400 Subject: [PATCH 1/2] change the repository clone_at option to checkout_branch to match libgit2 and assign it --- ext/rugged/rugged_repo.c | 6 +++++- test/repo_test.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ext/rugged/rugged_repo.c b/ext/rugged/rugged_repo.c index 54e5b2e13..5ceab125a 100644 --- a/ext/rugged/rugged_repo.c +++ b/ext/rugged/rugged_repo.c @@ -461,6 +461,10 @@ static void parse_clone_options(git_clone_options *ret, VALUE rb_options_hash, s if (RTEST(val)) ret->bare = 1; + val = rb_hash_aref(rb_options_hash, CSTR2SYM("checkout_branch")); + if (RTEST(val) && (TYPE(val) == T_STRING)) + ret->checkout_branch = StringValuePtr(val); + val = rb_hash_aref(rb_options_hash, CSTR2SYM("credentials")); if (RTEST(val)) { if (rb_obj_is_kind_of(val, rb_cRuggedCredPlaintext) || @@ -509,7 +513,7 @@ static void parse_clone_options(git_clone_options *ret, VALUE rb_options_hash, s * If +true+, the clone will be created as a bare repository. * Defaults to +false+. * - * :branch :: + * :checkout_branch :: * The name of a branch to checkout. Defaults to the remote's +HEAD+. * * :remote :: diff --git a/test/repo_test.rb b/test/repo_test.rb index 0cbfc5833..15413d0b4 100644 --- a/test/repo_test.rb +++ b/test/repo_test.rb @@ -450,6 +450,19 @@ def test_clone_with_progress assert_equal 1563, received_bytes end + def test_clone_with_branch + repo = Rugged::Repository.clone_at(@source_path, @tmppath, {:checkout_branch => "packed"}) + begin + assert_equal "what file?\n", File.read(File.join(@tmppath, "second.txt")) + assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.head.target_id + assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.ref("refs/heads/packed").target_id + assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/remotes/origin/master").target_id + assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.ref("refs/remotes/origin/packed").target_id + ensure + repo.close + end + end + def test_clone_quits_on_error begin Rugged::Repository.clone_at(@source_path, @tmppath, :callbacks => { From dc11a5b465cc0ce58f6012c6f450553021ec6850 Mon Sep 17 00:00:00 2001 From: Albert Sun Date: Mon, 24 Mar 2014 15:13:49 -0400 Subject: [PATCH 2/2] give val a different name --- ext/rugged/rugged_repo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/rugged/rugged_repo.c b/ext/rugged/rugged_repo.c index 5ceab125a..9f9a9ff9f 100644 --- a/ext/rugged/rugged_repo.c +++ b/ext/rugged/rugged_repo.c @@ -452,7 +452,7 @@ static int rugged__default_remote_credentials_cb( static void parse_clone_options(git_clone_options *ret, VALUE rb_options_hash, struct rugged_remote_cb_payload *remote_payload) { git_remote_callbacks remote_callbacks = GIT_REMOTE_CALLBACKS_INIT; - VALUE val; + VALUE val, checkout_branch_val; if (NIL_P(rb_options_hash)) return; @@ -461,9 +461,9 @@ static void parse_clone_options(git_clone_options *ret, VALUE rb_options_hash, s if (RTEST(val)) ret->bare = 1; - val = rb_hash_aref(rb_options_hash, CSTR2SYM("checkout_branch")); - if (RTEST(val) && (TYPE(val) == T_STRING)) - ret->checkout_branch = StringValuePtr(val); + checkout_branch_val = rb_hash_aref(rb_options_hash, CSTR2SYM("checkout_branch")); + if (RTEST(checkout_branch_val) && (TYPE(checkout_branch_val) == T_STRING)) + ret->checkout_branch = StringValuePtr(checkout_branch_val); val = rb_hash_aref(rb_options_hash, CSTR2SYM("credentials")); if (RTEST(val)) {