From 3f84eaf1857907690750297ba1a07389dff44cad Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 31 Jul 2025 22:57:02 +0100 Subject: [PATCH] Ignoring repositories --- CHANGELOG.md | 1 + internal/config/config.go | 1 + internal/repositories/update.go | 24 +++++++++++++++++++++++- todo.txt | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9764027..203a86e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ### Added - Set a default `depth` in config.yaml and remove the hard-coded value. +- Ignore repository paths using `ignores` in config.yaml. ## [0.1.0] diff --git a/internal/config/config.go b/internal/config/config.go index 6c0c41b..a583e90 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,6 +11,7 @@ import ( type Config struct { Depth string `yaml:"depth"` Directories []string `yaml:"directories"` + IgnoredRepos []string `yaml:"ignored"` } func getConfigPath() (string, error) { diff --git a/internal/repositories/update.go b/internal/repositories/update.go index 920a54d..dd933dd 100644 --- a/internal/repositories/update.go +++ b/internal/repositories/update.go @@ -4,13 +4,35 @@ import ( "fmt" "os" "os/exec" + "slices" "strings" + + "git-repo-updater/internal/config" + "git-repo-updater/internal/utils" ) func Update(repositoryPath string) error { + cfg, err := config.Load() + + if err != nil { + } + repositoryPath = strings.TrimSuffix(repositoryPath, "/.git") - err := os.Chdir(repositoryPath) + expandedIgnored := make([]string, 0, len(cfg.IgnoredRepos)) + for _, ignored := range cfg.IgnoredRepos { + if expanded, err := utils.ExpandPath(ignored); err == nil { + expandedIgnored = append(expandedIgnored, expanded) + } + } + + if slices.Contains(expandedIgnored, repositoryPath) { + fmt.Printf("Skipping %s as it's ignored\n", repositoryPath) + + return nil + } + + err = os.Chdir(repositoryPath) if err != nil { return fmt.Errorf("failed to change directory to %s: %w", repositoryPath, err) diff --git a/todo.txt b/todo.txt index 3637a5f..16a8ee0 100644 --- a/todo.txt +++ b/todo.txt @@ -2,6 +2,7 @@ * Update the repositories within each directory. * Make depth configurable per directory. * Set a default depth in config.yaml. +* Add excluding/ignoring a repository. Add unit tests. Add a `--dry-run` option.