@with_rw_repo('HEAD', bare=False)
    def test_heads(self, rwrepo):
        for head in rwrepo.heads:
            assert head.name
            assert head.path
            assert head.path in "refs/heads"
            prev_object = head.object
            cur_object = head.object
            assert prev_object == cur_object        # represent the same git object
            assert prev_object is not cur_object    # but are different instances

            writer = head.config_writer()
            tv = "testopt"
            writer.set_value(tv, 1)
            assert writer.get_value(tv) == 1
            writer.release()
            assert head.config_reader().get_value(tv) == 1
            writer = head.config_writer()
            writer.remove_option(tv)
            writer.release()

            # after the clone, we might still have a tracking branch setup
            head.set_tracking_branch(None)
            assert head.tracking_branch() is None
            remote_ref = rwrepo.remotes[0].refs[0]
            assert head.set_tracking_branch(remote_ref) is head
            assert head.tracking_branch() == remote_ref
            head.set_tracking_branch(None)
            assert head.tracking_branch() is None
        # END for each head

        # verify REFLOG gets altered
        head = rwrepo.head
        cur_head = head.ref
        cur_commit = cur_head.commit
        pcommit = cur_head.commit.parents[0].parents[0]
        hlog_len = len(head.log())
        blog_len = len(cur_head.log())
        assert head.set_reference(pcommit, 'detached head') is head
        # one new log-entry
        thlog = head.log()
        assert len(thlog) == hlog_len + 1
        assert thlog[-1].oldhexsha == cur_commit.hexsha
        assert thlog[-1].newhexsha == pcommit.hexsha

        # the ref didn't change though
        assert len(cur_head.log()) == blog_len

        # head changes once again, cur_head doesn't change
        head.set_reference(cur_head, 'reattach head')
        assert len(head.log()) == hlog_len + 2
        assert len(cur_head.log()) == blog_len

        # adjusting the head-ref also adjust the head, so both reflogs are
        # altered
        cur_head.set_commit(pcommit, 'changing commit')
        assert len(cur_head.log()) == blog_len + 1
        assert len(head.log()) == hlog_len + 3

        # with automatic dereferencing
        assert head.set_commit(cur_commit, 'change commit once again') is head
        assert len(head.log()) == hlog_len + 4
        assert len(cur_head.log()) == blog_len + 2

        # a new branch has just a single entry
        other_head = Head.create(rwrepo, 'mynewhead', pcommit, logmsg='new head created')
        log = other_head.log()
        assert len(log) == 1
        assert log[0].oldhexsha == pcommit.NULL_HEX_SHA
        assert log[0].newhexsha == pcommit.hexsha
dataset/ETHPy150Open gitpython-developers/GitPython/git/test/test_refs.py/TestRefs.test_heads/swapped operands of `in`