mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
discard old reflog commits when in new context
This commit is contained in:
@ -1118,10 +1118,11 @@ func (c *GitCommand) FetchRemote(remoteName string) error {
|
|||||||
|
|
||||||
// GetNewReflogCommits only returns the new reflog commits since the given lastReflogCommit
|
// GetNewReflogCommits only returns the new reflog commits since the given lastReflogCommit
|
||||||
// if none is passed (i.e. it's value is nil) then we get all the reflog commits
|
// if none is passed (i.e. it's value is nil) then we get all the reflog commits
|
||||||
func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, error) {
|
func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, bool, error) {
|
||||||
commits := make([]*Commit, 0)
|
commits := make([]*Commit, 0)
|
||||||
re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`)
|
re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`)
|
||||||
cmd := c.OSCommand.ExecutableFromString("git reflog --abbrev=20 --date=unix")
|
cmd := c.OSCommand.ExecutableFromString("git reflog --abbrev=20 --date=unix")
|
||||||
|
foundLastReflogCommit := false
|
||||||
err := RunLineOutputCmd(cmd, func(line string) (bool, error) {
|
err := RunLineOutputCmd(cmd, func(line string) (bool, error) {
|
||||||
match := re.FindStringSubmatch(line)
|
match := re.FindStringSubmatch(line)
|
||||||
if len(match) <= 1 {
|
if len(match) <= 1 {
|
||||||
@ -1138,6 +1139,7 @@ func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
if lastReflogCommit != nil && commit.Sha == lastReflogCommit.Sha && commit.UnixTimestamp == lastReflogCommit.UnixTimestamp {
|
if lastReflogCommit != nil && commit.Sha == lastReflogCommit.Sha && commit.UnixTimestamp == lastReflogCommit.UnixTimestamp {
|
||||||
|
foundLastReflogCommit = true
|
||||||
// after this point we already have these reflogs loaded so we'll simply return the new ones
|
// after this point we already have these reflogs loaded so we'll simply return the new ones
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@ -1146,10 +1148,10 @@ func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, e
|
|||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return commits, nil
|
return commits, foundLastReflogCommit, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) ConfiguredPager() string {
|
func (c *GitCommand) ConfiguredPager() string {
|
||||||
|
@ -52,12 +52,18 @@ func (gui *Gui) refreshReflogCommits() error {
|
|||||||
lastReflogCommit = gui.State.ReflogCommits[0]
|
lastReflogCommit = gui.State.ReflogCommits[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
commits, err := gui.GitCommand.GetNewReflogCommits(lastReflogCommit)
|
commits, foundLastReflogCommit, err := gui.GitCommand.GetNewReflogCommits(lastReflogCommit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if foundLastReflogCommit {
|
||||||
gui.State.ReflogCommits = append(commits, gui.State.ReflogCommits...)
|
gui.State.ReflogCommits = append(commits, gui.State.ReflogCommits...)
|
||||||
|
} else {
|
||||||
|
// if we haven't found it we're probably in a new repo so we don't want to
|
||||||
|
// retain the old reflog commits
|
||||||
|
gui.State.ReflogCommits = commits
|
||||||
|
}
|
||||||
|
|
||||||
if gui.getCommitsView().Context == "reflog-commits" {
|
if gui.getCommitsView().Context == "reflog-commits" {
|
||||||
return gui.renderReflogCommitsWithSelection()
|
return gui.renderReflogCommitsWithSelection()
|
||||||
|
Reference in New Issue
Block a user