diff options
author | zeripath <art27@cantab.net> | 2022-01-19 23:26:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 23:26:57 +0000 |
commit | 5cb0c9aa0d7eed087055b1efca79628957207d36 (patch) | |
tree | d117a514e1f17e5f6bfcda1be273f6a971112663 /modules/repository/generate.go | |
parent | 4563148a61ba892e8f2bb66342f00a950bcd5315 (diff) | |
download | gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip |
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git
commands run within the request context.
This now means that the if there is a git repo already open in the context it will be used instead of reopening it.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/repository/generate.go')
-rw-r--r-- | modules/repository/generate.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/modules/repository/generate.go b/modules/repository/generate.go index 3f83f51bb7..c7ba617919 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -99,7 +99,7 @@ func checkGiteaTemplate(tmpDir string) (*models.GiteaTemplate, error) { return gt, nil } -func generateRepoCommit(repo, templateRepo, generateRepo *repo_model.Repository, tmpDir string) error { +func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository, tmpDir string) error { commitTimeStr := time.Now().Format(time.RFC3339) authorSig := repo.Owner.NewGitSig() @@ -115,7 +115,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *repo_model.Repository, // Clone to temporary path and do the init commit. templateRepoPath := templateRepo.RepoPath() - if err := git.Clone(templateRepoPath, tmpDir, git.CloneRepoOptions{ + if err := git.Clone(ctx, templateRepoPath, tmpDir, git.CloneRepoOptions{ Depth: 1, Branch: templateRepo.DefaultBranch, }); err != nil { @@ -172,19 +172,19 @@ func generateRepoCommit(repo, templateRepo, generateRepo *repo_model.Repository, } } - if err := git.InitRepository(tmpDir, false); err != nil { + if err := git.InitRepository(ctx, tmpDir, false); err != nil { return err } repoPath := repo.RepoPath() - if stdout, err := git.NewCommand("remote", "add", "origin", repoPath). + if stdout, err := git.NewCommandContext(ctx, "remote", "add", "origin", repoPath). SetDescription(fmt.Sprintf("generateRepoCommit (git remote add): %s to %s", templateRepoPath, tmpDir)). RunInDirWithEnv(tmpDir, env); err != nil { log.Error("Unable to add %v as remote origin to temporary repo to %s: stdout %s\nError: %v", repo, tmpDir, stdout, err) return fmt.Errorf("git remote add: %v", err) } - return initRepoCommit(tmpDir, repo, repo.Owner, templateRepo.DefaultBranch) + return initRepoCommit(ctx, tmpDir, repo, repo.Owner, templateRepo.DefaultBranch) } func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository) (err error) { @@ -199,7 +199,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r } }() - if err = generateRepoCommit(repo, templateRepo, generateRepo, tmpDir); err != nil { + if err = generateRepoCommit(ctx, repo, templateRepo, generateRepo, tmpDir); err != nil { return fmt.Errorf("generateRepoCommit: %v", err) } @@ -209,7 +209,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r } repo.DefaultBranch = templateRepo.DefaultBranch - gitRepo, err := git.OpenRepository(repo.RepoPath()) + gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) if err != nil { return fmt.Errorf("openRepository: %v", err) } @@ -273,7 +273,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ } } - if err = checkInitRepository(owner.Name, generateRepo.Name); err != nil { + if err = checkInitRepository(ctx, owner.Name, generateRepo.Name); err != nil { return generateRepo, err } |