@@ -105,33 +105,33 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
105
105
}
106
106
wasEmpty = repo .IsEmpty
107
107
}
108
- if gitRepo == nil {
109
- var err error
110
- gitRepo , err = gitrepo .OpenRepository (ctx , repo )
108
+
109
+ if ! update .IsDelRef () {
110
+ if gitRepo == nil {
111
+ var err error
112
+ gitRepo , err = gitrepo .OpenRepository (ctx , repo )
113
+ if err != nil {
114
+ log .Error ("Failed to open repository: %s/%s Error: %v" , ownerName , repoName , err )
115
+ ctx .JSON (http .StatusInternalServerError , private.HookPostReceiveResult {
116
+ Err : fmt .Sprintf ("Failed to open repository: %s/%s Error: %v" , ownerName , repoName , err ),
117
+ })
118
+ return
119
+ }
120
+ }
121
+ commit , err := gitRepo .GetCommit (update .NewCommitID )
111
122
if err != nil {
112
- log .Error ("Failed to open repository: %s/%s Error: %v" , ownerName , repoName , err )
113
123
ctx .JSON (http .StatusInternalServerError , private.HookPostReceiveResult {
114
- Err : fmt .Sprintf ("Failed to open repository: %s/%s Error: %v" , ownerName , repoName , err ),
124
+ Err : fmt .Sprintf ("Failed to get commit %s in repository: %s/%s Error: %v" , update . NewCommitID , ownerName , repoName , err ),
115
125
})
116
126
return
117
127
}
118
- }
119
- var commit * git.Commit
120
- if ! opts .IsDelRef () {
121
- commit , err := gitRepo .GetCommit (update .NewCommitID )
122
- if err != nil {
123
- ctx .JSON (http .StatusInternalServerError , private.HookPostReceiveResult {
124
- Err : fmt .Sprintf ("Failed to get commit %s in repository: %s/%s Error: %v" , update .NewCommitID , ownerName , repoName , err ),
125
- })
126
- return
128
+ if err := repo_service .SyncBranchToDB (ctx , repo .ID , update .PusherID , update .RefFullName .BranchName (), commit ); err != nil {
129
+ ctx .JSON (http .StatusInternalServerError , private.HookPostReceiveResult {
130
+ Err : fmt .Sprintf ("Failed to sync branch to DB in repository: %s/%s Error: %v" , ownerName , repoName , err ),
131
+ })
132
+ return
127
133
}
128
134
}
129
- if err := repo_service .SyncBranchToDB (ctx , repo .ID , update .PusherID , update .RefFullName .BranchName (), commit ); err != nil {
130
- ctx .JSON (http .StatusInternalServerError , private.HookPostReceiveResult {
131
- Err : fmt .Sprintf ("Failed to sync branch to DB in repository: %s/%s Error: %v" , ownerName , repoName , err ),
132
- })
133
- return
134
- }
135
135
}
136
136
}
137
137
0 commit comments