@@ -52,8 +52,9 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
52
52
IsEmpty : ! opts .AutoInit ,
53
53
}
54
54
55
+ repoPath := repo_model .RepoPath (u .Name , repo .Name )
56
+
55
57
if err := db .WithTx (ctx , func (ctx context.Context ) error {
56
- repoPath := repo_model .RepoPath (u .Name , repo .Name )
57
58
isExist , err := util .IsExist (repoPath )
58
59
if err != nil {
59
60
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
75
76
if repo , err = repo_model .GetRepositoryByID (ctx , repo .ID ); err != nil {
76
77
return fmt .Errorf ("getRepositoryByID: %w" , err )
77
78
}
79
+ return nil
80
+ }); err != nil {
81
+ return nil , err
82
+ }
78
83
84
+ if err := func () error {
79
85
if err := adoptRepository (ctx , repoPath , repo , opts .DefaultBranch ); err != nil {
80
86
return fmt .Errorf ("adoptRepository: %w" , err )
81
87
}
@@ -84,23 +90,18 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
84
90
return fmt .Errorf ("checkDaemonExportOK: %w" , err )
85
91
}
86
92
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
-
94
93
if stdout , _ , err := git .NewCommand (ctx , "update-server-info" ).
95
94
RunStdString (& git.RunOpts {Dir : repoPath }); err != nil {
96
95
log .Error ("CreateRepository(git update-server-info) in %v: Stdout: %s\n Error: %v" , repo , stdout , err )
97
96
return fmt .Errorf ("CreateRepository(git update-server-info): %w" , err )
98
97
}
99
98
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 repository %s that could not be adopted: %v" , repo .FullName (), errDel )
102
+ }
101
103
return nil , err
102
104
}
103
-
104
105
notify_service .AdoptRepository (ctx , doer , u , repo )
105
106
106
107
return repo , nil
0 commit comments