|
|
@ -30,8 +30,8 @@ type ForkRepoOptions struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ForkRepository forks a repository
|
|
|
|
// ForkRepository forks a repository
|
|
|
|
func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo_model.Repository, err error) { |
|
|
|
func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts ForkRepoOptions) (*repo_model.Repository, error) { |
|
|
|
forkedRepo, err := repo_model.GetUserFork(opts.BaseRepo.ID, owner.ID) |
|
|
|
forkedRepo, err := repo_model.GetUserFork(ctx, opts.BaseRepo.ID, owner.ID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -91,24 +91,24 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo |
|
|
|
panic(panicErr) |
|
|
|
panic(panicErr) |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
err = db.WithTx(func(ctx context.Context) error { |
|
|
|
err = db.WithTx(func(txCtx context.Context) error { |
|
|
|
if err = models.CreateRepository(ctx, doer, owner, repo, false); err != nil { |
|
|
|
if err = models.CreateRepository(txCtx, doer, owner, repo, false); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = models.IncrementRepoForkNum(ctx, opts.BaseRepo.ID); err != nil { |
|
|
|
if err = models.IncrementRepoForkNum(txCtx, opts.BaseRepo.ID); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// copy lfs files failure should not be ignored
|
|
|
|
// copy lfs files failure should not be ignored
|
|
|
|
if err = models.CopyLFS(ctx, repo, opts.BaseRepo); err != nil { |
|
|
|
if err = models.CopyLFS(txCtx, repo, opts.BaseRepo); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
needsRollback = true |
|
|
|
needsRollback = true |
|
|
|
|
|
|
|
|
|
|
|
repoPath := repo_model.RepoPath(owner.Name, repo.Name) |
|
|
|
repoPath := repo_model.RepoPath(owner.Name, repo.Name) |
|
|
|
if stdout, err := git.NewCommand(ctx, |
|
|
|
if stdout, err := git.NewCommand(txCtx, |
|
|
|
"clone", "--bare", oldRepoPath, repoPath). |
|
|
|
"clone", "--bare", oldRepoPath, repoPath). |
|
|
|
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())). |
|
|
|
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())). |
|
|
|
RunInDirTimeout(10*time.Minute, ""); err != nil { |
|
|
|
RunInDirTimeout(10*time.Minute, ""); err != nil { |
|
|
@ -116,11 +116,11 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo |
|
|
|
return fmt.Errorf("git clone: %v", err) |
|
|
|
return fmt.Errorf("git clone: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := models.CheckDaemonExportOK(ctx, repo); err != nil { |
|
|
|
if err := models.CheckDaemonExportOK(txCtx, repo); err != nil { |
|
|
|
return fmt.Errorf("checkDaemonExportOK: %v", err) |
|
|
|
return fmt.Errorf("checkDaemonExportOK: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if stdout, err := git.NewCommand(ctx, "update-server-info"). |
|
|
|
if stdout, err := git.NewCommand(txCtx, "update-server-info"). |
|
|
|
SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())). |
|
|
|
SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())). |
|
|
|
RunInDir(repoPath); err != nil { |
|
|
|
RunInDir(repoPath); err != nil { |
|
|
|
log.Error("Fork Repository (git update-server-info) failed for %v:\nStdout: %s\nError: %v", repo, stdout, err) |
|
|
|
log.Error("Fork Repository (git update-server-info) failed for %v:\nStdout: %s\nError: %v", repo, stdout, err) |
|
|
@ -139,14 +139,14 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// even if below operations failed, it could be ignored. And they will be retried
|
|
|
|
// even if below operations failed, it could be ignored. And they will be retried
|
|
|
|
if err := models.UpdateRepoSize(db.DefaultContext, repo); err != nil { |
|
|
|
if err := models.UpdateRepoSize(ctx, repo); err != nil { |
|
|
|
log.Error("Failed to update size for repository: %v", err) |
|
|
|
log.Error("Failed to update size for repository: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
if err := repo_model.CopyLanguageStat(opts.BaseRepo, repo); err != nil { |
|
|
|
if err := repo_model.CopyLanguageStat(opts.BaseRepo, repo); err != nil { |
|
|
|
log.Error("Copy language stat from oldRepo failed: %v", err) |
|
|
|
log.Error("Copy language stat from oldRepo failed: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.RepoPath()) |
|
|
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Error("Open created git repository failed: %v", err) |
|
|
|
log.Error("Open created git repository failed: %v", err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|