|
|
|
@@ -520,12 +520,40 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err := updateRepoCommitCnt(ctx, repo); err != nil { |
|
|
|
log.Error("updateRepoCommitCnt failed:%v", err.Error(), ctx.Data["MsgID"]) |
|
|
|
} |
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, private.HookPostReceiveResult{ |
|
|
|
Results: results, |
|
|
|
RepoWasEmpty: wasEmpty, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func updateRepoCommitCnt(ctx *macaron.Context, repo *models.Repository) error { |
|
|
|
gitRepo, err := git.OpenRepository(repo.RepoPath()) |
|
|
|
if err != nil { |
|
|
|
log.Error("OpenRepository failed:%v", err.Error(), ctx.Data["MsgID"]) |
|
|
|
return err |
|
|
|
} |
|
|
|
defer gitRepo.Close() |
|
|
|
|
|
|
|
count, err := gitRepo.GetAllCommitsCount() |
|
|
|
if err != nil { |
|
|
|
log.Error("GetAllCommitsCount failed:%v", err.Error(), ctx.Data["MsgID"]) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
repo.NumCommit = count |
|
|
|
if err = models.UpdateRepositoryCols(repo, "num_commit"); err != nil { |
|
|
|
log.Error("UpdateRepositoryCols failed:%v", err.Error(), ctx.Data["MsgID"]) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// SetDefaultBranch updates the default branch |
|
|
|
func SetDefaultBranch(ctx *macaron.Context) { |
|
|
|
ownerName := ctx.Params(":owner") |
|
|
|
|