2018-09-19 11:15:29 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
// updateRecentRepoList registers the fact that we opened lazygit in this repo,
|
|
|
|
// so that we can open the same repo via the 'recent repos' menu
|
|
|
|
func (gui *Gui) updateRecentRepoList() error {
|
2022-08-15 14:59:34 +02:00
|
|
|
isBareRepo, err := gui.git.Status.IsBareRepo()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if isBareRepo {
|
2020-09-27 08:02:20 +02:00
|
|
|
// we could totally do this but it would require storing both the git-dir and the
|
|
|
|
// worktree in our recent repos list, which is a change that would need to be
|
|
|
|
// backwards compatible
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.Log.Info("Not appending bare repo to recent repo list")
|
2020-09-27 08:02:20 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
recentRepos := gui.c.GetAppState().RecentRepos
|
2018-09-19 11:15:29 +02:00
|
|
|
currentRepo, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-12-10 14:45:03 +02:00
|
|
|
known, recentRepos := newRecentReposList(recentRepos, currentRepo)
|
2021-12-29 02:50:20 +02:00
|
|
|
gui.IsNewRepo = known
|
2023-07-29 05:15:58 +02:00
|
|
|
// TODO: migrate this file to use forward slashes on all OSes for consistency
|
|
|
|
// (windows uses backslashes at the moment)
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.GetAppState().RecentRepos = recentRepos
|
|
|
|
return gui.c.SaveAppState()
|
2018-09-19 11:15:29 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 23:05:16 +02:00
|
|
|
// newRecentReposList returns a new repo list with a new entry but only when it doesn't exist yet
|
2018-12-10 14:45:03 +02:00
|
|
|
func newRecentReposList(recentRepos []string, currentRepo string) (bool, []string) {
|
|
|
|
isNew := true
|
2018-09-19 11:15:29 +02:00
|
|
|
newRepos := []string{currentRepo}
|
|
|
|
for _, repo := range recentRepos {
|
|
|
|
if repo != currentRepo {
|
2022-06-17 21:20:37 +02:00
|
|
|
if _, err := os.Stat(filepath.Join(repo, ".git")); err != nil {
|
2022-06-09 15:57:54 +02:00
|
|
|
continue
|
|
|
|
}
|
2018-09-19 11:15:29 +02:00
|
|
|
newRepos = append(newRepos, repo)
|
2018-12-10 14:45:03 +02:00
|
|
|
} else {
|
|
|
|
isNew = false
|
2018-09-19 11:15:29 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-10 14:45:03 +02:00
|
|
|
return isNew, newRepos
|
2018-09-19 11:15:29 +02:00
|
|
|
}
|