-
Notifications
You must be signed in to change notification settings - Fork 178
/
git.go
38 lines (30 loc) · 848 Bytes
/
git.go
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
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
// Use of this source code is governed by the license in the LICENSE file.
package git
import (
"strings"
"github.com/pkg/errors"
"go.jetpack.io/devbox/internal/cmdutil"
"go.jetpack.io/devbox/internal/fileutil"
)
func CloneToTmp(repo string) (string, error) {
tmpDir, err := fileutil.CreateDevboxTempDir()
if err != nil {
return "", err
}
if err := clone(repo, tmpDir); err != nil {
return "", err
}
return tmpDir, nil
}
func IsRepoURL(url string) bool {
// For now only support ssh
return strings.HasPrefix(url, "git@") ||
(strings.HasPrefix(url, "https://") && strings.HasSuffix(url, ".git"))
}
func clone(repo, dir string) error {
cmd := cmdutil.CommandTTY("git", "clone", repo, dir)
cmd.Dir = dir
err := cmd.Run()
return errors.WithStack(err)
}