mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add abstraction layer to check if the repository exists on disk (#33874)
Extract from #28966 This PR uses `gitrepo.IsRepositoryExist` instead of `util.IsExist` to detect whether the repository exist in disk. This will move `RepoPath` detail behind of package `gitrepo` to make it easier to do possible changes where storing the repositories. No code change
This commit is contained in:
@@ -52,12 +52,10 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
|
||||
IsEmpty: !opts.AutoInit,
|
||||
}
|
||||
|
||||
repoPath := repo_model.RepoPath(u.Name, repo.Name)
|
||||
|
||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
isExist, err := util.IsExist(repoPath)
|
||||
isExist, err := gitrepo.IsRepositoryExist(ctx, repo)
|
||||
if err != nil {
|
||||
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
||||
log.Error("Unable to check if %s exists. Error: %v", repo.FullName(), err)
|
||||
return err
|
||||
}
|
||||
if !isExist {
|
||||
@@ -82,7 +80,7 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
|
||||
}
|
||||
|
||||
if err := func() error {
|
||||
if err := adoptRepository(ctx, repoPath, repo, opts.DefaultBranch); err != nil {
|
||||
if err := adoptRepository(ctx, repo, opts.DefaultBranch); err != nil {
|
||||
return fmt.Errorf("adoptRepository: %w", err)
|
||||
}
|
||||
|
||||
@@ -91,7 +89,7 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
|
||||
}
|
||||
|
||||
if stdout, _, err := git.NewCommand("update-server-info").
|
||||
RunStdString(ctx, &git.RunOpts{Dir: repoPath}); err != nil {
|
||||
RunStdString(ctx, &git.RunOpts{Dir: repo.RepoPath()}); err != nil {
|
||||
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
|
||||
return fmt.Errorf("CreateRepository(git update-server-info): %w", err)
|
||||
}
|
||||
@@ -107,17 +105,17 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
func adoptRepository(ctx context.Context, repoPath string, repo *repo_model.Repository, defaultBranch string) (err error) {
|
||||
isExist, err := util.IsExist(repoPath)
|
||||
func adoptRepository(ctx context.Context, repo *repo_model.Repository, defaultBranch string) (err error) {
|
||||
isExist, err := gitrepo.IsRepositoryExist(ctx, repo)
|
||||
if err != nil {
|
||||
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
||||
log.Error("Unable to check if %s exists. Error: %v", repo.FullName(), err)
|
||||
return err
|
||||
}
|
||||
if !isExist {
|
||||
return fmt.Errorf("adoptRepository: path does not already exist: %s", repoPath)
|
||||
return fmt.Errorf("adoptRepository: path does not already exist: %s", repo.FullName())
|
||||
}
|
||||
|
||||
if err := repo_module.CreateDelegateHooks(repoPath); err != nil {
|
||||
if err := repo_module.CreateDelegateHooks(repo.RepoPath()); err != nil {
|
||||
return fmt.Errorf("createDelegateHooks: %w", err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user