• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AntonKosov / git-backups / 16737381085

05 Aug 2025 12:29AM UTC coverage: 84.685% (+34.7%) from 50.0%
16737381085

push

github

b9f9b6
AntonKosov
Added fetcher to clone and pull

Closes #39

22 of 26 new or added lines in 2 files covered. (84.62%)

7 existing lines in 1 file now uncovered.

94 of 111 relevant lines covered (84.68%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/internal/git/fetcher.go
1
package git
2

3
import (
4
        "context"
5
        "errors"
6
        "log/slog"
7
        "os"
8

9
        "github.com/AntonKosov/git-backups/internal/clog"
10
)
11

12
//counterfeiter:generate . GitWorker
13
type GitWorker interface {
14
        Clone(ctx context.Context, url, path string) error
15
        Fetch(ctx context.Context, path string) error
16
}
17

18
type Fetcher struct {
19
        worker GitWorker
20
}
21

22
func NewFetcher(worker GitWorker) Fetcher {
1✔
23
        return Fetcher{worker: worker}
1✔
24
}
1✔
25

26
func (f Fetcher) Run(ctx context.Context, url, targetFolder string) error {
1✔
27
        ctx = clog.Add(ctx, "URL", url, "target folder", targetFolder)
1✔
28
        exists, err := folderExists(targetFolder)
1✔
29
        if err != nil {
1✔
NEW
30
                slog.ErrorContext(ctx, "Failed to check folder", "error", err)
×
NEW
31
                return err
×
NEW
32
        }
×
33

34
        if exists {
2✔
35
                return f.worker.Fetch(ctx, targetFolder)
1✔
36
        }
1✔
37

38
        return f.worker.Clone(ctx, url, targetFolder)
1✔
39
}
40

41
func folderExists(folder string) (bool, error) {
1✔
42
        _, err := os.Stat(folder)
1✔
43
        if err == nil {
2✔
44
                return true, nil
1✔
45
        }
1✔
46
        var pathError *os.PathError
1✔
47
        if errors.As(err, &pathError) {
2✔
48
                return false, nil
1✔
49
        }
1✔
50

NEW
51
        return false, err
×
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc