Skip to content

checking out a detached HEAD breaks Repo.head.reference #2230

Description

@tiltingpenguin

While building this package for openSUSE and running the testsuite we encountered a lot of test failures like this

self = <git.HEAD "HEAD">

    def _get_reference(self) -> "Reference":
        """
        :return:
            :class:`~git.refs.reference.Reference` object we point to

        :raise TypeError:
            If this symbolic reference is detached, hence it doesn't point to a
            reference, but to a commit.
        """
        sha, target_ref_path = self._get_ref_info(self.repo, self.path)
        if target_ref_path is None:
>           raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
E           TypeError: HEAD is a detached symbolic reference as it points to '3481da9618e69063464c94447167d83bd45505a9'

git/refs/symbolic.py:446: TypeError

It seems that this only occurs when checking out a revision instead of a branch, aka when the ref in .git/HEAD points to a commit instead of something like ref: refs/heads/master.

Repo.head.reference in git/repo/base.py fails to resolve references to commit hashes which I would expect to work.

Also there is an unrelated problem where TestRemote.test_base hardcodes the branch name as "master" which leads to the test failing when checking out any other branch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions