mirror of
https://github.com/cooperspencer/gickup.git
synced 2025-05-10 17:25:34 +02:00
feat(local): Add mirror mode (#308)
* feat(local): Add mirror mode * fix: Add `.git` to the mirror repos too
This commit is contained in:
parent
06a97f1f8a
commit
eadd2f7347
5 changed files with 20 additions and 10 deletions
|
@ -269,6 +269,7 @@ destination:
|
|||
zip: true # zips the repository after cloned and removes the repository afterwards
|
||||
keep: 5 # only keeps x backups
|
||||
bare: true # clone the repositories as bare
|
||||
mirror: true # create mirror clones
|
||||
lfs: true # clone lfs repos, !! ATTENTION !! git and git-lfs must be installed on the system!
|
||||
s3:
|
||||
- endpoint: somewhere:9000 # whatever your s3 endpoint is
|
||||
|
|
|
@ -499,6 +499,10 @@
|
|||
"type": "boolean",
|
||||
"description": "clone the repository as a bare repository"
|
||||
},
|
||||
"mirror": {
|
||||
"type": "boolean",
|
||||
"description": "clone the repository as a mirror repository"
|
||||
},
|
||||
"lfs": {
|
||||
"type": "boolean",
|
||||
"description": "uses lfs to clone repositories"
|
||||
|
|
|
@ -22,17 +22,20 @@ func New() (GitCmd, error) {
|
|||
return GitCmd{CMD: "git"}, nil
|
||||
}
|
||||
|
||||
func (g GitCmd) Clone(url, reponame string, bare bool) error {
|
||||
func (g GitCmd) Clone(url, reponame string, bare bool, mirror bool) error {
|
||||
cmd := exec.Command(g.CMD, "clone", url, reponame)
|
||||
if bare {
|
||||
cmd.Args = append(cmd.Args, "--bare")
|
||||
}
|
||||
if mirror {
|
||||
cmd.Args = append(cmd.Args, "--mirror")
|
||||
}
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (g GitCmd) Pull(bare bool, repopath string) error {
|
||||
func (g GitCmd) Pull(bare bool, mirror bool, repopath string) error {
|
||||
var args = []string{}
|
||||
if bare {
|
||||
if bare || mirror {
|
||||
args = []string{"-C", repopath, "fetch", "--all"}
|
||||
} else {
|
||||
args = []string{"-C", repopath, "pull", "--all"}
|
||||
|
|
|
@ -50,7 +50,7 @@ func Locally(repo types.Repo, l types.Local, dry bool) bool {
|
|||
repo.Name = path.Join(repo.Hoster, repo.Owner, repo.Name)
|
||||
}
|
||||
|
||||
if l.Bare {
|
||||
if l.Bare || l.Mirror {
|
||||
repo.Name += ".git"
|
||||
}
|
||||
|
||||
|
@ -329,12 +329,12 @@ func updateRepository(reponame string, auth transport.AuthMethod, dry bool, l ty
|
|||
sub.Info().
|
||||
Msgf("pulling %s", types.Green(reponame))
|
||||
|
||||
err = gitc.Pull(l.Bare, filepath.Join(l.Path, reponame))
|
||||
err = gitc.Pull(l.Bare, l.Mirror, filepath.Join(l.Path, reponame))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if l.Bare {
|
||||
if l.Bare || l.Mirror {
|
||||
sub.Info().
|
||||
Msgf("fetching lfs files for %s", types.Green(reponame))
|
||||
|
||||
|
@ -355,7 +355,7 @@ func updateRepository(reponame string, auth transport.AuthMethod, dry bool, l ty
|
|||
}
|
||||
sub.Info().
|
||||
Msgf("pulling %s", types.Green(reponame))
|
||||
if !l.Bare {
|
||||
if !l.Bare && !l.Mirror {
|
||||
w, err := r.Worktree()
|
||||
if err != nil {
|
||||
if err == git.NoErrAlreadyUpToDate {
|
||||
|
@ -440,12 +440,12 @@ func cloneRepository(repo types.Repo, auth transport.AuthMethod, dry bool, l typ
|
|||
}
|
||||
}
|
||||
|
||||
err = gitc.Clone(url, filepath.Join(l.Path, repo.Name), l.Bare)
|
||||
err = gitc.Clone(url, filepath.Join(l.Path, repo.Name), l.Bare, l.Mirror)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if l.Bare {
|
||||
if l.Bare || l.Mirror {
|
||||
sub.Info().
|
||||
Msgf("fetching lfs files for %s", types.Green(repo.Name))
|
||||
|
||||
|
@ -460,6 +460,7 @@ func cloneRepository(repo types.Repo, auth transport.AuthMethod, dry bool, l typ
|
|||
URL: url,
|
||||
Auth: auth,
|
||||
SingleBranch: false,
|
||||
Mirror: l.Mirror,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -548,7 +549,7 @@ func TempClone(repo types.Repo, tempdir string) (*git.Repository, error) {
|
|||
repo.URL = strings.Replace(repo.URL, "https://", fmt.Sprintf("https://xyz:%s@", repo.Token), -1)
|
||||
}
|
||||
|
||||
err = gitc.Clone(repo.URL, tempdir, false)
|
||||
err = gitc.Clone(repo.URL, tempdir, false, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ func (dest Destination) Count() int {
|
|||
// Local TODO.
|
||||
type Local struct {
|
||||
Bare bool `yaml:"bare"`
|
||||
Mirror bool `yaml:"mirror" default:"false"`
|
||||
Path string `yaml:"path"`
|
||||
Structured bool `yaml:"structured"`
|
||||
Zip bool `yaml:"zip"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue