diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-28 10:45:44 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-28 11:59:45 +1100 |
commit | 19604214d7da76a685085961095c1d7b2ad5f5cb (patch) | |
tree | e2301265e05b5b3938c9774eae3f78e71914a25d /pkg/commands | |
parent | f7add8d788604743b334c72b784c487968b99867 (diff) |
discard old reflog commits when in new context
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 3b49a254e..5ec4bb70a 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -1118,10 +1118,11 @@ func (c *GitCommand) FetchRemote(remoteName string) error { // 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 -func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, error) { +func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, bool, error) { commits := make([]*Commit, 0) re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`) cmd := c.OSCommand.ExecutableFromString("git reflog --abbrev=20 --date=unix") + foundLastReflogCommit := false err := RunLineOutputCmd(cmd, func(line string) (bool, error) { match := re.FindStringSubmatch(line) 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 { + foundLastReflogCommit = true // after this point we already have these reflogs loaded so we'll simply return the new ones return true, nil } @@ -1146,10 +1148,10 @@ func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, e return false, nil }) if err != nil { - return nil, err + return nil, false, err } - return commits, nil + return commits, foundLastReflogCommit, nil } func (c *GitCommand) ConfiguredPager() string { |