Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ext/rugged/rugged_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -461,6 +461,10 @@ static void parse_clone_options(git_clone_options *ret, VALUE rb_options_hash, s
if (RTEST(val))
ret->bare = 1;

checkout_branch_val = rb_hash_aref(rb_options_hash, CSTR2SYM("checkout_branch"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just reuse val here, instead of introducing another variable?

if (RTEST(checkout_branch_val) && (TYPE(checkout_branch_val) == T_STRING))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I feel that something like the following would be a bit better:

if (!NIL_P(checkout_branch_val)) {
    CHECK_TYPE(checkout_branch_val, T_STRING);
    ret->checkout_branch = StringValueCStr(rb_path);
}

ret->checkout_branch = StringValuePtr(checkout_branch_val);

val = rb_hash_aref(rb_options_hash, CSTR2SYM("credentials"));
if (RTEST(val)) {
if (rb_obj_is_kind_of(val, rb_cRuggedCredPlaintext) ||
Expand Down Expand Up @@ -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 ::
Expand Down
13 changes: 13 additions & 0 deletions test/repo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to the Ruby 1.9 Hash Syntax? Like: checkout_branch: "packed".

begin
assert_equal "what file?\n", File.read(File.join(@tmppath, "second.txt"))
assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.head.target_id

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be enough if you check that:

assert_equal "refs/heads/packed", repo.references["HEAD"].target_id

The other assertions you have in this test don't really have anything to do with the :checkout_branch option.

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 => {
Expand Down