@@ -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,24 +90,19 @@ 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
SetDescription (fmt .Sprintf ("CreateRepository(git update-server-info): %s" , repoPath )).
96
95
RunStdString (& git.RunOpts {Dir : repoPath }); err != nil {
97
96
log .Error ("CreateRepository(git update-server-info) in %v: Stdout: %s\n Error: %v" , repo , stdout , err )
98
97
return fmt .Errorf ("CreateRepository(git update-server-info): %w" , err )
99
98
}
100
99
return nil
101
- }); err != nil {
100
+ }(); err != nil {
101
+ if errDel := DeleteRepository (ctx , doer , repo , false /* no notify */ ); errDel != nil {
102
+ log .Error ("Failed to delete repository %s that could not be adopted: %v" , repo .FullName (), errDel )
103
+ }
102
104
return nil , err
103
105
}
104
-
105
106
notify_service .AdoptRepository (ctx , doer , u , repo )
106
107
107
108
return repo , nil
0 commit comments