File tree Expand file tree Collapse file tree 3 files changed +42
-8
lines changed
Expand file tree Collapse file tree 3 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -122,8 +122,18 @@ func (c *Command) RunInDir(dir string) (string, error) {
122122 return string (stdout ), nil
123123}
124124
125+ // RunTimeout executes the command in defualt working directory with given timeout,
126+ // and returns stdout in string and error (combined with stderr).
127+ func (c * Command ) RunTimeout (timeout time.Duration ) (string , error ) {
128+ stdout , err := c .RunInDirTimeout (timeout , "" )
129+ if err != nil {
130+ return "" , err
131+ }
132+ return string (stdout ), nil
133+ }
134+
125135// Run executes the command in defualt working directory
126136// and returns stdout in string and error (combined with stderr).
127137func (c * Command ) Run () (string , error ) {
128- return c .RunInDir ( "" )
138+ return c .RunTimeout ( - 1 )
129139}
Original file line number Diff line number Diff line change @@ -11,14 +11,12 @@ import (
1111
1212var (
1313 // Debug enables verbose logging on everything.
14- Debug = true
14+ // This should be false in case Gogs starts in SSH mode.
15+ Debug = false
1516 Prefix = "[git-shell] "
1617)
1718
1819func log (format string , args ... interface {}) {
19- // FIXME: need a better way handle log, such as write to file.
20- return
21-
2220 if ! Debug {
2321 return
2422 }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
1111 "os"
1212 "path"
1313 "path/filepath"
14+ "time"
1415)
1516
1617// Repository represents a Git repository.
@@ -65,12 +66,37 @@ func OpenRepository(repoPath string) (*Repository, error) {
6566 return & Repository {Path : repoPath }, nil
6667}
6768
69+ type CloneRepoOptions struct {
70+ Mirror bool
71+ Bare bool
72+ Quiet bool
73+ Timeout time.Duration
74+ }
75+
6876// Clone clones original repository to target path.
69- func Clone (from , to string ) error {
77+ func Clone (from , to string , opts CloneRepoOptions ) ( err error ) {
7078 toDir := path .Dir (to )
71- os .MkdirAll (toDir , os .ModePerm )
79+ if err = os .MkdirAll (toDir , os .ModePerm ); err != nil {
80+ return err
81+ }
82+
83+ cmd := NewCommand ("clone" )
84+ if opts .Mirror {
85+ cmd .AddArguments ("--mirror" )
86+ }
87+ if opts .Bare {
88+ cmd .AddArguments ("--bare" )
89+ }
90+ if opts .Quiet {
91+ cmd .AddArguments ("--quiet" )
92+ }
93+ cmd .AddArguments (from , to )
94+
95+ if opts .Timeout <= 0 {
96+ opts .Timeout = - 1
97+ }
7298
73- _ , err := NewCommand ( "clone" , from , to ). Run ( )
99+ _ , err = cmd . RunTimeout ( opts . Timeout )
74100 return err
75101}
76102
You can’t perform that action at this time.
0 commit comments