def test_ambiguous_head(self):
     r = {
         b"refs/heads/ambig4": 'bla',
         b"refs/remotes/ambig4": 'bla',
         b"refs/remotes/ambig4/HEAD": "bla"
     }
     self.assertEqual(b"refs/heads/ambig4", parse_ref(r, b"ambig4"))
Пример #2
0
def update_head(repo, target, detached=False, new_branch=None):
    """Update HEAD to point at a new branch/commit.

    Note that this does not actually update the working tree.

    :param repo: Path to the repository
    :param detach: Create a detached head
    :param target: Branch or committish to switch to
    :param new_branch: New branch to create
    """
    with open_repo_closing(repo) as r:
        if new_branch is not None:
            to_set = _make_branch_ref(new_branch)
        else:
            to_set = b"HEAD"
        if detached:
            # TODO(jelmer): Provide some way so that the actual ref gets
            # updated rather than what it points to, so the delete isn't
            # necessary.
            del r.refs[to_set]
            r.refs[to_set] = parse_commit(r, target).id
        else:
            r.refs.set_symbolic_ref(to_set, parse_ref(r, target))
        if new_branch is not None:
            r.refs.set_symbolic_ref(b"HEAD", to_set)
 def test_ambiguous_tag(self):
     r = {
         b"refs/tags/ambig3": 'bla',
         b"refs/heads/ambig3": 'bla',
         b"refs/remotes/ambig3": 'bla',
         b"refs/remotes/ambig3/HEAD": "bla"
     }
     self.assertEqual(b"refs/tags/ambig3", parse_ref(r, b"ambig3"))
 def test_tags_partial(self):
     r = {b"refs/tags/foo": "bla"}
     self.assertEqual(b"refs/tags/foo", parse_ref(r, b"tags/foo"))
 def test_heads_partial(self):
     r = {b"refs/heads/foo": "bla"}
     self.assertEqual(b"refs/heads/foo", parse_ref(r, b"heads/foo"))
 def test_ambiguous_remote_head(self):
     r = {b"refs/remotes/ambig6/HEAD": "bla"}
     self.assertEqual(b"refs/remotes/ambig6/HEAD", parse_ref(r, b"ambig6"))
 def test_ambiguous_remote(self):
     r = {b"refs/remotes/ambig5": 'bla', b"refs/remotes/ambig5/HEAD": "bla"}
     self.assertEqual(b"refs/remotes/ambig5", parse_ref(r, b"ambig5"))