From b869b3ccd0197209a75e6f8e64127f2eb22dc9d6 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Sat, 14 Dec 2024 11:38:33 -0800 Subject: [PATCH] feat(git): add git branch to CacheKey resolves #6012 --- src/config/segment.go | 5 +++-- src/segments/git.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/config/segment.go b/src/config/segment.go index c86f6262..0cf5f9da 100644 --- a/src/config/segment.go +++ b/src/config/segment.go @@ -223,9 +223,10 @@ func (segment *Segment) restoreCache() bool { return false } - data, OK := segment.env.Session().Get(segment.cacheKey()) + cacheKey := segment.cacheKey() + data, OK := segment.env.Session().Get(cacheKey) if !OK { - log.Debug("no cache found for segment: ", segment.Name()) + log.Debugf("no cache found for segment: %s, key: %s", segment.Name(), cacheKey) return false } diff --git a/src/segments/git.go b/src/segments/git.go index 7c0b16c6..bf9aca96 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -217,7 +217,9 @@ func (g *Git) CacheKey() (string, bool) { return "", false } - return dir.Path, true + ref := g.FileContents(dir.Path, "HEAD") + ref = strings.Replace(ref, "ref: refs/heads/", "", 1) + return fmt.Sprintf("%s@%s", dir.Path, ref), true } func (g *Git) Commit() *Commit {