Write a reflog message when moving branch refs

Branches that lazygit forwards to their upstream move by a direct ref
write, so no git command turns up in their reflog to explain it. Until
now the entry had no message either, leaving `git reflog <branch>` with
nothing but a blank line about it. Name lazygit and what it did, so that
a branch which moved on its own can be traced.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-27 11:00:36 +02:00
co-authored by Claude Opus 5
parent 83bff569a0
commit 9183269ee8
2 changed files with 7 additions and 3 deletions
+5 -1
View File
@@ -440,9 +440,13 @@ func (self *BranchCommands) previousUpstreamValues(upstreamRef string) []string
return values
}
func (self *BranchCommands) UpdateBranchRefs(updateCommands string) error {
// Moves branches by writing refs directly. The reflog message is what
// `git reflog <branch>` shows for the update; it is the only hint about who
// moved the branch, as no git command shows up in the reflog for this.
func (self *BranchCommands) UpdateBranchRefs(updateCommands string, reflogMessage string) error {
cmdArgs := NewGitCmd("update-ref").
Arg("--stdin").
Arg("-m", reflogMessage).
ToArgv()
return self.cmd.New(cmdArgs).SetStdin(updateCommands).Run()
@@ -577,7 +577,7 @@ func (self *BranchesHelper) forwardBranches(toForward []*branchToForward) error
if updateCommands != "" {
self.c.LogCommand(strings.TrimRight(updateCommands, "\n"), false)
if err := self.c.Git().Branch.UpdateBranchRefs(updateCommands); err != nil {
if err := self.c.Git().Branch.UpdateBranchRefs(updateCommands, "lazygit: update to upstream branch"); err != nil {
return err
}
}
@@ -647,7 +647,7 @@ func (self *BranchesHelper) AutoForwardBranches(background bool) error {
self.c.LogAction(self.c.Tr.Actions.AutoForwardBranches)
self.c.LogCommand(strings.TrimRight(updateCommands, "\n"), false)
err := self.c.Git().Branch.UpdateBranchRefs(updateCommands)
err := self.c.Git().Branch.UpdateBranchRefs(updateCommands, "lazygit: fast-forward to upstream branch")
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES}, Background: background})