@@ -70,9 +70,17 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo
7070 if err := repo_module .CreateRepositoryByExample (ctx , doer , u , repo , true , false ); err != nil {
7171 return err
7272 }
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 {
7481 return fmt .Errorf ("createDelegateHooks: %w" , err )
7582 }
83+
7684 if err := repo_module .CheckDaemonExportOK (ctx , repo ); err != nil {
7785 return fmt .Errorf ("checkDaemonExportOK: %w" , err )
7886 }
@@ -95,12 +103,12 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo
95103 return nil , err
96104 }
97105
98- notification .NotifyCreateRepository (ctx , doer , u , repo )
106+ notification .NotifyAdoptRepository (ctx , doer , u , repo )
99107
100108 return repo , nil
101109}
102110
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 ) {
104112 isExist , err := util .IsExist (repoPath )
105113 if err != nil {
106114 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
114122 return fmt .Errorf ("createDelegateHooks: %w" , err )
115123 }
116124
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-
123125 repo .IsEmpty = false
124126
125127 // 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
129131 }
130132 defer gitRepo .Close ()
131133
132- if len (opts . DefaultBranch ) > 0 {
133- repo .DefaultBranch = opts . DefaultBranch
134+ if len (defaultBranch ) > 0 {
135+ repo .DefaultBranch = defaultBranch
134136
135137 if err = gitRepo .SetDefaultBranch (repo .DefaultBranch ); err != nil {
136138 return fmt .Errorf ("setDefaultBranch: %w" , err )
0 commit comments