mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 11:28:24 +00:00 
			
		
		
		
	Migrations: Use Process Manager to create own Context (#13793)
This commit is contained in:
		| @@ -32,6 +32,7 @@ var ( | ||||
| 	GitExecutable = "git" | ||||
|  | ||||
| 	// DefaultContext is the default context to run git commands in | ||||
| 	// will be overwritten by Init with HammerContext | ||||
| 	DefaultContext = context.Background() | ||||
|  | ||||
| 	gitVersion *version.Version | ||||
|   | ||||
| @@ -8,6 +8,7 @@ package git | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"container/list" | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| @@ -166,19 +167,24 @@ type CloneRepoOptions struct { | ||||
|  | ||||
| // Clone clones original repository to target path. | ||||
| func Clone(from, to string, opts CloneRepoOptions) (err error) { | ||||
| 	return CloneWithContext(DefaultContext, from, to, opts) | ||||
| } | ||||
|  | ||||
| // CloneWithContext clones original repository to target path. | ||||
| func CloneWithContext(ctx context.Context, from, to string, opts CloneRepoOptions) (err error) { | ||||
| 	cargs := make([]string, len(GlobalCommandArgs)) | ||||
| 	copy(cargs, GlobalCommandArgs) | ||||
| 	return CloneWithArgs(from, to, cargs, opts) | ||||
| 	return CloneWithArgs(ctx, from, to, cargs, opts) | ||||
| } | ||||
|  | ||||
| // CloneWithArgs original repository to target path. | ||||
| func CloneWithArgs(from, to string, args []string, opts CloneRepoOptions) (err error) { | ||||
| func CloneWithArgs(ctx context.Context, from, to string, args []string, opts CloneRepoOptions) (err error) { | ||||
| 	toDir := path.Dir(to) | ||||
| 	if err = os.MkdirAll(toDir, os.ModePerm); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	cmd := NewCommandNoGlobals(args...).AddArguments("clone") | ||||
| 	cmd := NewCommandContextNoGlobals(ctx, args...).AddArguments("clone") | ||||
| 	if opts.Mirror { | ||||
| 		cmd.AddArguments("--mirror") | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user