Skip to content

Commit 05663a0

Browse files
committed
Add bare repo mirroring
Signed-off-by: Richard Nixon <[email protected]>
1 parent cdd2db0 commit 05663a0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ Finally, make sure you have an up to date command line version of `git` installe
3939
* Scroll down in `settings` to `Developer Settings` and create a `personal access token (classic)`
4040
* Grant the token sufficient rights to access your github orgs/repos and configure SSO if necessary (just like we did for the SSH key)
4141

42+
## Bare mirroring (optional)
43+
44+
If `BITSYNC_MIRROR` is set to `true` then cloning will happen with the `--mirror` git option. This has the effects
45+
46+
* Repo's will be deleted if they exist
47+
* The repos will be cloned bare with the mirror flag set
48+
* All branches and tags will be mirrored
49+
50+
This is effectively a full archive of the repo, but it cannot be used for normal git workflows as it has the following git config options set
51+
52+
```aiignore
53+
[core]
54+
bare = true
55+
56+
[remote "origin"]
57+
fetch = +refs/*:refs/*
58+
mirror = true
59+
```
60+
4261
## Using
4362

4463
Pass the credentials, and optional org lists, as environment variables and sync your repos.

main.go

+17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,24 @@ import (
99
"time"
1010
)
1111

12+
func mirrorGitRepo(repoDir, cloneUrl, mainBranch string) {
13+
fmt.Printf(" Bare mirror %s from %s\n", repoDir, cloneUrl)
14+
out, err := exec.Command("rm", "-rf", repoDir).CombinedOutput()
15+
if err != nil {
16+
fmt.Println("Error during delete directory: " + string(out))
17+
}
18+
out, err = exec.Command("git", "clone", "--mirror", cloneUrl, repoDir).CombinedOutput()
19+
if err != nil {
20+
fmt.Println("Error during mirror: " + string(out))
21+
}
22+
}
23+
1224
func cloneOrSyncGitRepo(repoDir, cloneUrl, mainBranch string) {
25+
mirror := os.Getenv("BITSYNC_MIRROR")
26+
if mirror == "true" {
27+
mirrorGitRepo(repoDir, cloneUrl, mainBranch)
28+
return
29+
}
1330
fmt.Printf(" Processing git repo %s from %s\n", repoDir, cloneUrl)
1431
if _, err := os.Stat(repoDir); err != nil {
1532
out, err := exec.Command("git", "clone", cloneUrl, repoDir).CombinedOutput()

0 commit comments

Comments
 (0)