Skip to content

Commit 4de2248

Browse files
committed
fix
1 parent 06f1065 commit 4de2248

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

services/repository/adopt.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
5252
IsEmpty: !opts.AutoInit,
5353
}
5454

55+
repoPath := repo_model.RepoPath(u.Name, repo.Name)
56+
5557
if err := db.WithTx(ctx, func(ctx context.Context) error {
56-
repoPath := repo_model.RepoPath(u.Name, repo.Name)
5758
isExist, err := util.IsExist(repoPath)
5859
if err != nil {
5960
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
@@ -75,7 +76,12 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
7576
if repo, err = repo_model.GetRepositoryByID(ctx, repo.ID); err != nil {
7677
return fmt.Errorf("getRepositoryByID: %w", err)
7778
}
79+
return nil
80+
}); err != nil {
81+
return nil, err
82+
}
7883

84+
if err := func() error {
7985
if err := adoptRepository(ctx, repoPath, repo, opts.DefaultBranch); err != nil {
8086
return fmt.Errorf("adoptRepository: %w", err)
8187
}
@@ -84,23 +90,18 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
8490
return fmt.Errorf("checkDaemonExportOK: %w", err)
8591
}
8692

87-
// Initialize Issue Labels if selected
88-
if len(opts.IssueLabels) > 0 {
89-
if err := repo_module.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
90-
return fmt.Errorf("InitializeLabels: %w", err)
91-
}
92-
}
93-
9493
if stdout, _, err := git.NewCommand(ctx, "update-server-info").
9594
RunStdString(&git.RunOpts{Dir: repoPath}); err != nil {
9695
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
9796
return fmt.Errorf("CreateRepository(git update-server-info): %w", err)
9897
}
9998
return nil
100-
}); err != nil {
99+
}(); err != nil {
100+
if errDel := DeleteRepository(ctx, doer, repo, false /* no notify */); errDel != nil {
101+
log.Error("Failed to delete adopt-failed repository %s: %v", repoPath, errDel)
102+
}
101103
return nil, err
102104
}
103-
104105
notify_service.AdoptRepository(ctx, doer, u, repo)
105106

106107
return repo, nil

0 commit comments

Comments
 (0)