Skip to content

Commit

Permalink
create temporary directory to clone into
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer committed Aug 15, 2023
1 parent 6c10cfc commit 5207a59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 2 additions & 3 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/melbahja/goph"
"github.com/mholt/archiver"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -421,12 +420,12 @@ func VerifyHost(host string, remote net.Addr, key gossh.PublicKey) error {
return goph.AddKnownHost(host, remote, key, "")
}

func TempClone(repo types.Repo) (*git.Repository, error) {
func TempClone(repo types.Repo, tempdir string) (*git.Repository, error) {
auth := &http.BasicAuth{
Username: "xyz",
Password: repo.Token,
}
r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
r, err := git.PlainClone(tempdir, false, &git.CloneOptions{
URL: repo.URL,
Auth: auth,
})
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,16 @@ func backup(repos []types.Repo, conf *types.Conf) {
Msgf("mirroring %s to %s", types.Blue(r.Name), "https://github.com")

if !cli.Dry {
temprepo, err := local.TempClone(r)
tempdir, err := os.MkdirTemp(os.TempDir(), fmt.Sprintf("github-%x", repotime))
if err != nil {
log.Error().
Str("stage", "tempclone").
Str("url", r.URL).
Msg(err.Error())
continue
}
defer os.RemoveAll(tempdir)
temprepo, err := local.TempClone(r, tempdir)
if err != nil {
log.Error().
Str("stage", "tempclone").
Expand Down

0 comments on commit 5207a59

Please sign in to comment.