-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathgit_repository_clone.go
More file actions
62 lines (53 loc) · 1.48 KB
/
git_repository_clone.go
File metadata and controls
62 lines (53 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"log"
"sync"
)
// handleGitRepositoryClone clones or updates all repositories for the configured service
func handleGitRepositoryClone(client any, c *appConfig) error {
// Check if git is available before proceeding
if err := checkGitAvailability(); err != nil {
return err
}
// Used for waiting for all the goroutines to finish before exiting
var wg sync.WaitGroup
defer wg.Wait()
// Set global variables used by helper functions
useHTTPSClone = &c.useHTTPSClone
ignorePrivate = &c.ignorePrivate
tokens := make(chan bool, MaxConcurrentClones)
gitHostUsername = getUsername(client, c.service)
if len(gitHostUsername) == 0 && c.ignorePrivate && c.useHTTPSClone {
return fmt.Errorf("your Git host's username is needed for backing up private repositories via HTTPS")
}
repositories, err := getRepositories(
client,
c.service,
c.githubRepoType,
c.githubNamespaceWhitelist,
c.gitlabProjectVisibility,
c.gitlabProjectMembershipType,
c.ignoreFork,
c.forgejoRepoType,
)
if err != nil {
return err
}
if len(repositories) == 0 {
return fmt.Errorf("no repositories retrieved")
}
log.Printf("Backing up %v repositories now..\n", len(repositories))
for _, repo := range repositories {
tokens <- true
wg.Add(1)
go func(repo *Repository) {
stdoutStderr, err := backUp(c.backupDir, repo, c.bare, &wg)
if err != nil {
log.Printf("Error backing up %s: %s\n", repo.Name, stdoutStderr)
}
<-tokens
}(repo)
}
return nil
}