Permalink
Browse files

branch: reference is valid for set_upstream

  • Loading branch information...
1 parent 3bfcd60 commit a38ab349b523357529fd30eea62456c3f72fe485 @nvloff nvloff committed Jul 31, 2013
Showing with 19 additions and 3 deletions.
  1. +4 −3 ext/rugged/rugged_branch.c
  2. +15 −0 test/branch_test.rb
@@ -416,7 +416,8 @@ static VALUE rb_git_branch_upstream(VALUE self)
*
* Set the upstream configuration for a given local branch.
*
- * Takes a local or remote Rugged::Branch instance
+ * Takes a local or remote Rugged::Branch instance or a Rugged::Reference
+ * pointing to a branch.
*/
static VALUE rb_git_branch_set_upstream(VALUE self, VALUE rb_branch)
{
@@ -425,8 +426,8 @@ static VALUE rb_git_branch_set_upstream(VALUE self, VALUE rb_branch)
Data_Get_Struct(self, git_reference, branch);
if (!NIL_P(rb_branch)) {
- if (!rb_obj_is_kind_of(rb_branch, rb_cRuggedBranch))
- rb_raise(rb_eTypeError, "Expecting a Rugged::Branch instance");
+ if (!rb_obj_is_kind_of(rb_branch, rb_cRuggedReference))
+ rb_raise(rb_eTypeError, "Expecting a Rugged::Reference instance");
Data_Get_Struct(rb_branch, git_reference, target_branch);
View
@@ -236,6 +236,21 @@ def test_branch_set_upstream_invalid
end
end
+ def test_branch_set_upstream_with_reference
+ branch = @repo.create_branch('test_branch',
+ '5b5b025afb0b4c913b4c338a42934a3863bf3644')
+ branch.upstream = Rugged::Reference.lookup(@repo, "refs/heads/master")
+ assert_equal 'master', branch.upstream.name
+ end
+
+ def test_branch_set_upstream_with_tag_reference
+ branch = @repo.create_branch('test_branch',
+ '5b5b025afb0b4c913b4c338a42934a3863bf3644')
+ assert_raises Rugged::InvalidError do
+ branch.upstream = Rugged::Reference.lookup(@repo, "refs/tags/v1.0")
+ end
+ end
+
def test_branch_set_upstream_local
branch = @repo.create_branch('test_branch',
'5b5b025afb0b4c913b4c338a42934a3863bf3644')

0 comments on commit a38ab34

Please sign in to comment.