summaryrefslogtreecommitdiffstats
path: root/modules/repository
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-10-14 17:07:53 +0100
committerGitHub <noreply@github.com>2021-10-14 18:07:53 +0200
commita20ccec369e0ad7023cb77a480569e82fa5ada76 (patch)
tree26979dd57a0bebe4aeafbaa912073622b5d70f4c /modules/repository
parent9c2b7a196e6e546650ed687b3e0992f6d5a11c33 (diff)
downloadgitea-a20ccec369e0ad7023cb77a480569e82fa5ada76.tar.gz
gitea-a20ccec369e0ad7023cb77a480569e82fa5ada76.zip
Ensure that git daemon export ok is created for mirrors (#17243) (#17306)
Backport #17243 There is an issue with #16508 where it appears that create repo requires that the repo does not exist. This causes #17241 where an error is reported because of this. This PR fixes this and also runs update-server-info for mirrors and generated repos. Fix #17241 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/repository')
-rw-r--r--modules/repository/adopt.go3
-rw-r--r--modules/repository/create.go4
-rw-r--r--modules/repository/fork.go7
-rw-r--r--modules/repository/generate.go11
-rw-r--r--modules/repository/repo.go15
5 files changed, 38 insertions, 2 deletions
diff --git a/modules/repository/adopt.go b/modules/repository/adopt.go
index 321e6ab767..cdcf7104e0 100644
--- a/modules/repository/adopt.go
+++ b/modules/repository/adopt.go
@@ -66,6 +66,9 @@ func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mode
if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil {
return fmt.Errorf("createDelegateHooks: %v", err)
}
+ if err := repo.CheckDaemonExportOKCtx(ctx); err != nil {
+ return fmt.Errorf("checkDaemonExportOK: %v", err)
+ }
// Initialize Issue Labels if selected
if len(opts.IssueLabels) > 0 {
diff --git a/modules/repository/create.go b/modules/repository/create.go
index 5eac03836e..8065543d83 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -103,6 +103,10 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
}
}
+ if err := repo.CheckDaemonExportOKCtx(ctx); err != nil {
+ return fmt.Errorf("checkDaemonExportOK: %v", err)
+ }
+
if stdout, err := git.NewCommand("update-server-info").
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
RunInDir(repoPath); err != nil {
diff --git a/modules/repository/fork.go b/modules/repository/fork.go
index 6025faca33..4cff4c24f8 100644
--- a/modules/repository/fork.go
+++ b/modules/repository/fork.go
@@ -95,14 +95,17 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
needsRollback = true
repoPath := models.RepoPath(owner.Name, repo.Name)
- if stdout, err := git.NewCommand(
- "clone", "--bare", oldRepoPath, repoPath).
+ if stdout, err := git.NewCommand("clone", "--bare", oldRepoPath, repoPath).
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", oldRepo.FullName(), repo.FullName())).
RunInDirTimeout(10*time.Minute, ""); err != nil {
log.Error("Fork Repository (git clone) Failed for %v (from %v):\nStdout: %s\nError: %v", repo, oldRepo, stdout, err)
return fmt.Errorf("git clone: %v", err)
}
+ if err := repo.CheckDaemonExportOKCtx(ctx); err != nil {
+ return fmt.Errorf("checkDaemonExportOK: %v", err)
+ }
+
if stdout, err := git.NewCommand("update-server-info").
SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())).
RunInDir(repoPath); err != nil {
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index 1ba457fb3a..a7adce4d02 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -275,5 +275,16 @@ func GenerateRepository(ctx models.DBContext, doer, owner *models.User, template
return generateRepo, err
}
+ if err = generateRepo.CheckDaemonExportOKCtx(ctx); err != nil {
+ return generateRepo, fmt.Errorf("checkDaemonExportOK: %v", err)
+ }
+
+ if stdout, err := git.NewCommand("update-server-info").
+ SetDescription(fmt.Sprintf("GenerateRepository(git update-server-info): %s", repoPath)).
+ RunInDir(repoPath); err != nil {
+ log.Error("GenerateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", generateRepo, stdout, err)
+ return generateRepo, fmt.Errorf("error in GenerateRepository(git update-server-info): %v", err)
+ }
+
return generateRepo, nil
}
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index 08531c04ed..45308ad162 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -95,6 +95,21 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models.
}
}
+ if repo.OwnerID == u.ID {
+ repo.Owner = u
+ }
+
+ if err = repo.CheckDaemonExportOK(); err != nil {
+ return repo, fmt.Errorf("checkDaemonExportOK: %v", err)
+ }
+
+ if stdout, err := git.NewCommandContext(ctx, "update-server-info").
+ SetDescription(fmt.Sprintf("MigrateRepositoryGitData(git update-server-info): %s", repoPath)).
+ RunInDir(repoPath); err != nil {
+ log.Error("MigrateRepositoryGitData(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
+ return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %v", err)
+ }
+
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
return repo, fmt.Errorf("OpenRepository: %v", err)