@@ -70,9 +70,17 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo
70
70
if err := repo_module .CreateRepositoryByExample (ctx , doer , u , repo , true , false ); err != nil {
71
71
return err
72
72
}
73
- if err := adoptRepository (ctx , repoPath , doer , repo , opts ); err != nil {
73
+
74
+ // Re-fetch the repository from database before updating it (else it would
75
+ // override changes that were done earlier with sql)
76
+ if repo , err = repo_model .GetRepositoryByID (ctx , repo .ID ); err != nil {
77
+ return fmt .Errorf ("getRepositoryByID: %w" , err )
78
+ }
79
+
80
+ if err := adoptRepository (ctx , repoPath , doer , repo , opts .DefaultBranch ); err != nil {
74
81
return fmt .Errorf ("createDelegateHooks: %w" , err )
75
82
}
83
+
76
84
if err := repo_module .CheckDaemonExportOK (ctx , repo ); err != nil {
77
85
return fmt .Errorf ("checkDaemonExportOK: %w" , err )
78
86
}
@@ -95,12 +103,12 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo
95
103
return nil , err
96
104
}
97
105
98
- notification .NotifyCreateRepository (ctx , doer , u , repo )
106
+ notification .NotifyAdoptRepository (ctx , doer , u , repo )
99
107
100
108
return repo , nil
101
109
}
102
110
103
- func adoptRepository (ctx context.Context , repoPath string , u * user_model.User , repo * repo_model.Repository , opts repo_module. CreateRepoOptions ) (err error ) {
111
+ func adoptRepository (ctx context.Context , repoPath string , u * user_model.User , repo * repo_model.Repository , defaultBranch string ) (err error ) {
104
112
isExist , err := util .IsExist (repoPath )
105
113
if err != nil {
106
114
log .Error ("Unable to check if %s exists. Error: %v" , repoPath , err )
@@ -114,12 +122,6 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
114
122
return fmt .Errorf ("createDelegateHooks: %w" , err )
115
123
}
116
124
117
- // Re-fetch the repository from database before updating it (else it would
118
- // override changes that were done earlier with sql)
119
- if repo , err = repo_model .GetRepositoryByID (ctx , repo .ID ); err != nil {
120
- return fmt .Errorf ("getRepositoryByID: %w" , err )
121
- }
122
-
123
125
repo .IsEmpty = false
124
126
125
127
// Don't bother looking this repo in the context it won't be there
@@ -129,8 +131,8 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
129
131
}
130
132
defer gitRepo .Close ()
131
133
132
- if len (opts . DefaultBranch ) > 0 {
133
- repo .DefaultBranch = opts . DefaultBranch
134
+ if len (defaultBranch ) > 0 {
135
+ repo .DefaultBranch = defaultBranch
134
136
135
137
if err = gitRepo .SetDefaultBranch (repo .DefaultBranch ); err != nil {
136
138
return fmt .Errorf ("setDefaultBranch: %w" , err )
0 commit comments