1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-27 12:32:37 +02:00

Re-determine existing main branches if mainBranches config changed

This commit is contained in:
Stefan Haller 2024-07-30 19:38:36 +02:00
parent 3d6d677453
commit fd8e480363
2 changed files with 23 additions and 4 deletions

View File

@ -18,6 +18,8 @@ type MainBranches struct {
// depending on which one exists for a given bare name. // depending on which one exists for a given bare name.
existingMainBranches []string existingMainBranches []string
previousMainBranches []string
cmd oscommands.ICmdObjBuilder cmd oscommands.ICmdObjBuilder
mutex *deadlock.Mutex mutex *deadlock.Mutex
} }
@ -40,8 +42,11 @@ func (self *MainBranches) Get() []string {
self.mutex.Lock() self.mutex.Lock()
defer self.mutex.Unlock() defer self.mutex.Unlock()
if self.existingMainBranches == nil { configuredMainBranches := self.c.UserConfig().Git.MainBranches
self.existingMainBranches = self.determineMainBranches()
if self.existingMainBranches == nil || !utils.EqualSlices(self.previousMainBranches, configuredMainBranches) {
self.existingMainBranches = self.determineMainBranches(configuredMainBranches)
self.previousMainBranches = configuredMainBranches
} }
return self.existingMainBranches return self.existingMainBranches
@ -71,11 +76,10 @@ func (self *MainBranches) GetMergeBase(refName string) string {
return ignoringWarnings(output) return ignoringWarnings(output)
} }
func (self *MainBranches) determineMainBranches() []string { func (self *MainBranches) determineMainBranches(configuredMainBranches []string) []string {
var existingBranches []string var existingBranches []string
var wg sync.WaitGroup var wg sync.WaitGroup
configuredMainBranches := self.c.UserConfig().Git.MainBranches
existingBranches = make([]string, len(configuredMainBranches)) existingBranches = make([]string, len(configuredMainBranches))
for i, branchName := range configuredMainBranches { for i, branchName := range configuredMainBranches {

View File

@ -179,3 +179,18 @@ func Shift[T any](slice []T) (T, []T) {
slice = slice[1:] slice = slice[1:]
return value, slice return value, slice
} }
// Compares two slices for equality
func EqualSlices[T comparable](slice1 []T, slice2 []T) bool {
if len(slice1) != len(slice2) {
return false
}
for i := range slice1 {
if slice1[i] != slice2[i] {
return false
}
}
return true
}