Compare commits

...

20 commits
0.1.0 ... main

Author SHA1 Message Date
19591ad8e1 Update README
All checks were successful
/ check (push) Successful in 2m0s
2025-09-05 10:04:35 +01:00
6323576826 Update README
All checks were successful
/ check (push) Successful in 25s
2025-09-04 21:35:09 +01:00
8175f54ddd Update CHANGELOG
All checks were successful
/ check (push) Successful in 4s
2025-08-05 01:40:14 +01:00
b162228efd go mod tidy
All checks were successful
/ check (push) Successful in 5s
2025-08-05 01:36:15 +01:00
d98e648dca Update module paths to Forgejo
All checks were successful
/ check (push) Successful in 4s
2025-08-01 09:36:37 +01:00
959f92dea2 Update todo.txt
All checks were successful
/ check (push) Successful in 2s
2025-08-01 09:30:00 +01:00
9515ec0e29 Create Nix package
All checks were successful
/ check (push) Successful in 7s
2025-08-01 09:23:11 +01:00
9ec56012c2 Add TestExpandPath
All checks were successful
/ check (push) Successful in 15s
2025-07-31 23:59:31 +01:00
9755abdfd3 Use just
All checks were successful
/ check (push) Successful in 2s
2025-07-31 23:50:59 +01:00
cf3d8636e2 Revert "Create update_test.go"
All checks were successful
/ check (push) Successful in 2s
This reverts commit 31d313c6a9.
2025-07-31 23:50:21 +01:00
80ab07e86e Add justfile 2025-07-31 23:47:44 +01:00
739a3972eb Configure CI pipeline
Some checks failed
/ check (push) Failing after 3s
2025-07-31 23:35:46 +01:00
31d313c6a9 Create update_test.go 2025-07-31 23:33:30 +01:00
74f2ebfa57 Create .gitignore 2025-07-31 23:10:06 +01:00
3a94768343 Add missing TODOs 2025-07-31 23:06:47 +01:00
9f4ad8d959 Add config.yaml example 2025-07-31 22:59:57 +01:00
3f84eaf185 Ignoring repositories 2025-07-31 22:57:02 +01:00
0ee35feeb1 Make the default depth configurable 2025-07-31 22:40:54 +01:00
f6983c78d0 Update CHANGELOG.md 2025-07-31 22:12:48 +01:00
c3da4461fa Create README.md 2025-07-31 22:07:38 +01:00
16 changed files with 153 additions and 10 deletions

View file

@ -0,0 +1,7 @@
on: push
jobs:
check:
runs-on: nixos
steps:
- uses: actions/checkout@v4
- run: nix develop -c just test

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/git-repo-updater
/result

View file

@ -6,8 +6,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
## [Unreleased]
Nothing yet.
## [0.2.0] (2025-08-05)
### Added
- Set a default `depth` in config.yaml and remove the hard-coded value.
- Ignore repository paths using `ignores` in config.yaml.
## Changed
- Update module paths to my Forgejo instance (`code.oliverdavies.uk`).
## [0.1.0] (2025-07-31)
### Added
- Load a list of directories from a configuration file (`~/.config/git-repo-updater/config.yaml`).
- Configure the depth to search in each directory by appending it to the path - e.g. (`~/Code:3`).
[unreleased]: https://code.oliverdavies.uk/opdavies/git-repo-updater/commits/branch/main
[unreleased]: https://code.oliverdavies.uk/opdavies/git-repo-updater/compare/0.2.0...main
[0.2.0]: https://code.oliverdavies.uk/opdavies/git-repo-updater/compare/0.1.0...0.2.0
[0.1.0]: https://code.oliverdavies.uk/opdavies/git-repo-updater/releases/tag/0.1.0

23
README.md Normal file
View file

@ -0,0 +1,23 @@
# git-repo-updater
`git-repo-updater` is an CLI program that finds and updates Git repositories in specified directories.
## Configuration
`git-repo-updater` is configurable using a configuration file at `~/.config/git-repo-updater/config.yaml`.
For example:
```yaml
# The number of levels to search.
depth: 3
# A list of directories to search in.
directories:
- ~/Code/code.oliverdavies.uk
- ~/Code/github.com
# A list of repositories to ignore and not update.
ignored:
- ~/Code/github.com/nixos/nixpkgs
```

13
config.yaml.example Normal file
View file

@ -0,0 +1,13 @@
# The default depth in each directory to search for Git repositories.
depth: 2
# A list of directories to search in.
directories:
- ~/Code/forgejo:3
- ~/Code/github:3
# A list of repository paths to ignore (not update).
ignored:
- ~/Code/github/nixos/nixpkgs
# vim: ft=yaml

View file

@ -12,6 +12,7 @@
packages = with pkgs; [
go
gopls
just
];
};
};

View file

@ -0,0 +1,11 @@
{
perSystem =
{ pkgs, ... }:
{
packages.default = pkgs.buildGoModule {
name = "git-repo-updater";
src = ../.;
vendorHash = "sha256-g+yaVIx4jxpAQ/+WrGKxhVeliYx7nLQe/zsGpxV4Fn4=";
};
};
}

4
go.mod
View file

@ -1,5 +1,5 @@
module git-repo-updater
module code.oliverdavies.uk/opdavies/git-repo-updater
go 1.24.5
require gopkg.in/yaml.v3 v3.0.1 // indirect
require gopkg.in/yaml.v3 v3.0.1

1
go.sum
View file

@ -1,3 +1,4 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -9,7 +9,9 @@ import (
)
type Config struct {
Depth string `yaml:"depth"`
Directories []string `yaml:"directories"`
IgnoredRepos []string `yaml:"ignored"`
}
func getConfigPath() (string, error) {

View file

@ -6,7 +6,8 @@ import (
"os/exec"
"strings"
"git-repo-updater/internal/utils"
"code.oliverdavies.uk/opdavies/git-repo-updater/internal/config"
"code.oliverdavies.uk/opdavies/git-repo-updater/internal/utils"
)
func FindInDirectory(dir string) (string, error) {
@ -36,10 +37,16 @@ func FindInDirectory(dir string) (string, error) {
}
func splitPath(repoPath string) (string, string) {
cfg, err := config.Load()
if err != nil {
// TODO
}
parts := strings.SplitN(repoPath, ":", 2)
repoPath = parts[0]
depth := "2"
depth := cfg.Depth
if len(parts) == 2 {
return parts[0], parts[1]

View file

@ -4,13 +4,36 @@ import (
"fmt"
"os"
"os/exec"
"slices"
"strings"
"code.oliverdavies.uk/opdavies/git-repo-updater/internal/config"
"code.oliverdavies.uk/opdavies/git-repo-updater/internal/utils"
)
func Update(repositoryPath string) error {
cfg, err := config.Load()
if err != nil {
// TODO
}
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)

View file

@ -0,0 +1,26 @@
package utils_test
import (
"os"
"path/filepath"
"testing"
"code.oliverdavies.uk/opdavies/git-repo-updater/internal/utils"
)
func TestExpandPath(t *testing.T) {
home, _ := os.UserHomeDir()
input := "~/Code/my-repo"
expected := filepath.Join(home, "Code/my-repo")
result, err := utils.ExpandPath(input)
if err != nil {
t.Errorf("ExpandPath(%q) returned error: %v", input, err)
}
if result != expected {
t.Errorf("ExpandPath(%q) = %q; want %q", input, result, expected)
}
}

5
justfile Normal file
View file

@ -0,0 +1,5 @@
@default:
just --list
test:
go test ./... -v

View file

@ -4,8 +4,8 @@ import (
"log"
"strings"
"git-repo-updater/internal/config"
"git-repo-updater/internal/repositories"
"code.oliverdavies.uk/opdavies/git-repo-updater/internal/config"
"code.oliverdavies.uk/opdavies/git-repo-updater/internal/repositories"
)
func main() {

View file

@ -1,9 +1,13 @@
* Load directories from a configuration file
* Update the repositories within each directory.
* Make depth configurable per directory.
* Set a default depth in config.yaml.
* Add excluding/ignoring a repository.
* Add Nix package.
Set a default depth in config.yaml.
Add unit tests.
Add a `--dry-run` option.
Complete README.
Add Nix package.
Filtering repos by path at runtime?
grep -r --exclude-dir=.git TODO .