mirror of
https://github.com/go-gitea/git.git
synced 2026-07-01 20:34:42 -04:00
improve log and clone repo command
This commit is contained in:
+11
-1
@@ -122,8 +122,18 @@ func (c *Command) RunInDir(dir string) (string, error) {
|
||||
return string(stdout), nil
|
||||
}
|
||||
|
||||
// RunTimeout executes the command in defualt working directory with given timeout,
|
||||
// and returns stdout in string and error (combined with stderr).
|
||||
func (c *Command) RunTimeout(timeout time.Duration) (string, error) {
|
||||
stdout, err := c.RunInDirTimeout(timeout, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(stdout), nil
|
||||
}
|
||||
|
||||
// Run executes the command in defualt working directory
|
||||
// and returns stdout in string and error (combined with stderr).
|
||||
func (c *Command) Run() (string, error) {
|
||||
return c.RunInDir("")
|
||||
return c.RunTimeout(-1)
|
||||
}
|
||||
|
||||
@@ -11,14 +11,12 @@ import (
|
||||
|
||||
var (
|
||||
// Debug enables verbose logging on everything.
|
||||
Debug = true
|
||||
// This should be false in case Gogs starts in SSH mode.
|
||||
Debug = false
|
||||
Prefix = "[git-shell] "
|
||||
)
|
||||
|
||||
func log(format string, args ...interface{}) {
|
||||
// FIXME: need a better way handle log, such as write to file.
|
||||
return
|
||||
|
||||
if !Debug {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Repository represents a Git repository.
|
||||
@@ -65,12 +66,37 @@ func OpenRepository(repoPath string) (*Repository, error) {
|
||||
return &Repository{Path: repoPath}, nil
|
||||
}
|
||||
|
||||
// Clone clones original repository to target path.
|
||||
func Clone(from, to string) error {
|
||||
toDir := path.Dir(to)
|
||||
os.MkdirAll(toDir, os.ModePerm)
|
||||
type CloneRepoOptions struct {
|
||||
Mirror bool
|
||||
Bare bool
|
||||
Quiet bool
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
_, err := NewCommand("clone", from, to).Run()
|
||||
// Clone clones original repository to target path.
|
||||
func Clone(from, to string, opts CloneRepoOptions) (err error) {
|
||||
toDir := path.Dir(to)
|
||||
if err = os.MkdirAll(toDir, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := NewCommand("clone")
|
||||
if opts.Mirror {
|
||||
cmd.AddArguments("--mirror")
|
||||
}
|
||||
if opts.Bare {
|
||||
cmd.AddArguments("--bare")
|
||||
}
|
||||
if opts.Quiet {
|
||||
cmd.AddArguments("--quiet")
|
||||
}
|
||||
cmd.AddArguments(from, to)
|
||||
|
||||
if opts.Timeout <= 0 {
|
||||
opts.Timeout = -1
|
||||
}
|
||||
|
||||
_, err = cmd.RunTimeout(opts.Timeout)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user