Skip to content

allow Repository.set_head on unborn branches? #1374

Closed
@calestyo

Description

@calestyo

Hey.

I work on an empty repo that may have been created with git init (and thus it's .git/HEAD contains ref: refs/heads/master.

Now I want to write some commit but to a branch other than the default branch master.

I had kinda hoped that I could simply use repo.set_head("refs/heads/mybranch") and when I then repo.create_commit("HEAD",... it would use that.

But set_head already fails when the branch doesn't exist yet.

From what I could see from the sources, set_head uses libgit2’s git_repository_set_head() and that indeed seems to be documented as being usable with unborn branches:

If the provided reference points to a branch, the HEAD will point to that branch, staying attached, or become attached if it isn't yet. If the branch doesn't exist yet, no error will be return. The HEAD will then be attached to an unborn branch.

Any way to get that with pygit2?

Thanks,
Chris.

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