Skip to content

Repository.checkout('refs/heads/<head name>') with an orphan master branch results in exception #669

Closed
@nacc

Description

@nacc

In my repository, master has no commits (nor will it ever) and it seems like, without checking, Repository.checkout() uses the current branch (which might be the orphaned master)'s head, but I don't understand why, as from_ is not referred to again in the file.

        head = self.lookup_reference('HEAD')
        if head.type == C.GIT_REF_SYMBOLIC:
            from_ = self.head.shorthand
        else:
            from_ = head.target.hex

In my repository, this results in an exception and ubuntu/devel is present but not switched to.

$ git branch
  ubuntu/devel
Traceback (most recent call last):
  File "/home/nacc/work/usd-importer/usd/git_repository.py", line 453, in checkout
    self._local_repo.checkout('refs/heads/%s' % ref)
  File "/usr/lib/python3/dist-packages/pygit2/repository.py", line 284, in checkout
    from_ = self.head.shorthand
_pygit2.GitError: Reference 'refs/heads/master' not found

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