Skip to content

Renaming the current branch doesn't cause a message to be written to the HEAD reflog #4292

Open

Description

@jgrosso

In the case that the currently checked-out branch is renamed, Git core has logic to write to HEAD's reflog instead of only the ref-specific reflog (https://github.com/git/git/blob/e0aaa1b6532cfce93d87af9bc813fb2e7a7ce9d7/refs/files-backend.c#L2156-L2186). libgit2, however, only writes to the ref-specific reflog.

Reproduction steps

  1. Rename the currently checked-out branch via git_reference_rename (for example, check out development and rename it to develop).

Expected behavior

  • The reflog for the new name of the branch should be written to (for example, .git/logs/refs/heads/develop should contain branch: renamed...).
  • The reflog for HEAD should be written to (for example, .git/logs/HEAD should contain branch: renamed....

Actual behavior

  • The reflog for the new name of the branch is written to (for example, .git/logs/refs/heads/develop should contain branch: renamed...).
  • The reflog for HEAD is not written to (for example, .git/logs/HEAD should contain branch: renamed....

Version of libgit2 (release number or SHA1)

v0.25.1

Operating system(s) tested

macOS

Activity

  1. tiennou commented on Jul 17, 2017

    @tiennou
    Contributor

    Just a heads up, I think you want git_branch_move (eg. git branch -m develop) instead of git_reference_rename (eg. git update-ref development refs/heads/develop). I haven't checked what the reflog show in that case though, so YMMV.

  2. jgrosso commented on Jul 17, 2017

    @jgrosso
    Author

    @tiennou Thanks! IIRC, git_branch_move calls git_reference_rename under the hood; while I'm not 100% sure of that, my testing did show git_branch_move to have the same problem with the reflog.

  3. tiennou commented on Jul 17, 2017

    @tiennou
    Contributor

    Just checked, and there's still only the reflog line added by git_repository_set_head in the HEAD reflog. Hopefully, I'll have a preliminary PR soon-ish.

    (Sorry for the spam, I rebased the test and pushed the wrong one 😟)

  4. added a commit that references this issue on Jul 17, 2017
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