Skip to content

Commit 428f04e

Browse files
committed
Use ~/mirrors instead of ~/repos for mirrors
Signed-off-by: Richard Nixon <[email protected]>
1 parent 05663a0 commit 428f04e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ Finally, make sure you have an up to date command line version of `git` installe
4343

4444
If `BITSYNC_MIRROR` is set to `true` then cloning will happen with the `--mirror` git option. This has the effects
4545

46-
* Repo's will be deleted if they exist
46+
* Repo's will be deleted before cloning if they exist
4747
* The repos will be cloned bare with the mirror flag set
4848
* All branches and tags will be mirrored
49+
* Mirrors will be placed under `~/mirrors` instead of `~/repos`
4950

5051
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
5152

main.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ func cloneOrSyncGitRepo(repoDir, cloneUrl, mainBranch string) {
5555
func processGitHubRepo(repo GitHubRepository) {
5656
homeDir, err := os.UserHomeDir()
5757
checkErr(err)
58-
gitHubOrgPath := filepath.Join(homeDir, "repos", "github", repo.Owner.Login)
59-
gitHubRepoPath := filepath.Join(homeDir, "repos", "github", repo.Owner.Login, repo.Name)
58+
var gitHubRepoPath, gitHubOrgPath string
59+
mirror := os.Getenv("BITSYNC_MIRROR")
60+
if mirror == "true" {
61+
gitHubOrgPath = filepath.Join(homeDir, "mirrors", "github", repo.Owner.Login)
62+
gitHubRepoPath = filepath.Join(homeDir, "mirrors", "github", repo.Owner.Login, repo.Name)
63+
64+
} else {
65+
gitHubOrgPath = filepath.Join(homeDir, "repos", "github", repo.Owner.Login)
66+
gitHubRepoPath = filepath.Join(homeDir, "repos", "github", repo.Owner.Login, repo.Name)
67+
}
6068
err = os.MkdirAll(gitHubOrgPath, 0750)
6169
checkErr(err)
6270
cloneOrSyncGitRepo(gitHubRepoPath, repo.SSHUrl, repo.DefaultBranch)
@@ -94,8 +102,16 @@ func processGitHubOrgs() {
94102
func processBitBucketRepo(workspace string, repo BitbucketRepository) {
95103
homeDir, err := os.UserHomeDir()
96104
checkErr(err)
97-
BitBucketProjectPath := filepath.Join(homeDir, "repos", "bitbucket", workspace, repo.Project.Key)
98-
BitBucketRepoPath := filepath.Join(homeDir, "repos", "bitbucket", workspace, repo.Project.Key, repo.Slug)
105+
var BitBucketRepoPath, BitBucketProjectPath string
106+
mirror := os.Getenv("BITSYNC_MIRROR")
107+
if mirror == "true" {
108+
BitBucketProjectPath = filepath.Join(homeDir, "mirrors", "bitbucket", workspace, repo.Project.Key)
109+
BitBucketRepoPath = filepath.Join(homeDir, "mirrors", "bitbucket", workspace, repo.Project.Key, repo.Slug)
110+
111+
} else {
112+
BitBucketProjectPath = filepath.Join(homeDir, "repos", "bitbucket", workspace, repo.Project.Key)
113+
BitBucketRepoPath = filepath.Join(homeDir, "repos", "bitbucket", workspace, repo.Project.Key, repo.Slug)
114+
}
99115
BitBucketCloneUrl := "[email protected]:" + workspace + "/" + repo.Slug
100116
err = os.MkdirAll(BitBucketProjectPath, 0750)
101117
checkErr(err)

0 commit comments

Comments
 (0)