Skip to content

fix: git push hook post receive - #38089

Merged
wxiaoguang merged 3 commits into
go-gitea:mainfrom
wxiaoguang:fix-git-push
Jun 13, 2026
Merged

wxiaoguang merged 3 commits into
go-gitea:mainfrom
wxiaoguang:fix-git-push

Conversation

@wxiaoguang

@wxiaoguang wxiaoguang commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
  • fix incorrect delayWriter call (there is already a defer call)
  • split HookPostReceive into small functions
  • fix incorrect HookPostReceiveResult response for errors
  • fix incorrect AddRepoToLicenseUpdaterQueue call
  • make sure repo home and branches page can work without default branch
  • make sure default branch is always synchronized between database and git repo, and fix FIXME

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 12, 2026
@wxiaoguang
wxiaoguang force-pushed the fix-git-push branch 5 times, most recently from 9b820e2 to 347e0bd Compare June 12, 2026 11:51
@wxiaoguang
wxiaoguang requested a review from Copilot June 12, 2026 11:54
@wxiaoguang wxiaoguang mentioned this pull request Jun 12, 2026
@wxiaoguang wxiaoguang changed the title fix: git push next: fix: git push hook post receive Jun 12, 2026
@wxiaoguang wxiaoguang changed the title next: fix: git push hook post receive fix: git push hook post receive Jun 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes and hardens the git push / hook post-receive pipeline, with a focus on synchronizing branch/default-branch state between Git and the database, and making repo UI routes behave better when the default branch is missing.

Changes:

  • Fix post-receive processing by refactoring HookPostReceive into smaller helpers, improving error responses, and syncing branches/default branch.
  • Update push/branch handling so default-branch-related cache/license updates occur correctly and branches pages can render without a default branch.
  • Simplify hook result payloads and improve hook CLI batching/output handling (including replacing custom discard writer with io.Discard).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
services/repository/push.go Sync default-branch-related cache/license update behavior during pushes.
services/repository/branch.go Allow loading branches even when the default branch row is missing in DB.
services/context/repo.go Adjust default-branch commit resolution behavior during repo context initialization.
services/context/private.go Add PrivateError helper for consistent internal API error responses.
routers/web/repo/branch.go Make branches page tolerate missing default branch by using an optional default branch.
routers/private/hook_post_receive.go Refactor and harden post-receive: sync branches/default branch, unify error responses, simplify trailer logic.
routers/private/hook_post_receive_test.go Update test to call the renamed/refactored PR-merge handler.
modules/private/hook.go Simplify HookPostReceiveResult response structure.
modules/git/repo_commit.go Change branch/tag commit resolution to use ref names (tag resolution currently incorrect).
cmd/hook.go Fix delayed writer usage and batch hook-post-receive calls; use io.Discard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/git/repo_commit.go
Comment thread services/context/repo.go
Comment thread services/repository/branch.go Outdated
Comment thread routers/private/hook_post_receive.go
Comment thread routers/web/repo/branch.go
@wxiaoguang
wxiaoguang force-pushed the fix-git-push branch 3 times, most recently from 7b970fd to cdc7620 Compare June 12, 2026 12:21
@wxiaoguang
wxiaoguang requested a review from Copilot June 12, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Comment thread services/context/repo.go
Comment thread routers/private/hook_post_receive.go
Comment thread routers/private/hook_post_receive.go
Comment thread routers/private/hook_post_receive.go
Comment thread services/repository/push.go Outdated
Comment thread services/repository/push.go
Comment thread routers/private/hook_post_receive.go
@wxiaoguang

Copy link
Copy Markdown
Contributor Author
image

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 12, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 13, 2026
@wxiaoguang
wxiaoguang enabled auto-merge (squash) June 13, 2026 04:40
@wxiaoguang
wxiaoguang merged commit 1b3b4bd into go-gitea:main Jun 13, 2026
23 checks passed
@GiteaBot GiteaBot added this to the 1.28.0 milestone Jun 13, 2026
@lunny lunny modified the milestones: 1.28.0, 1.27.0 Jun 13, 2026
@wxiaoguang
wxiaoguang deleted the fix-git-push branch June 13, 2026 05:16
zeekay pushed a commit to hanzoai/forge that referenced this pull request Jul 26, 2026
* fix incorrect delayWriter call (there is already a defer call)
* split HookPostReceive into small functions
* fix incorrect HookPostReceiveResult response for errors
* fix incorrect AddRepoToLicenseUpdaterQueue call
* make sure repo home and branches page can work without default branch
* make sure default branch is always synchronized between database and
git repo, and fix FIXME
richmahn added a commit to unfoldingWord/dcs that referenced this pull request Aug 18, 2026
…s/v1.27

Conflict: routers/private/default_branch.go was deleted upstream by
go-gitea/gitea#38965 (backport of #38964, "remove dead code
SetDefaultBranch"). Accepted the deletion: the DCS
ProcessDoor43MetadataForRepo() call it held had been unreachable since
go-gitea/gitea#38089 removed the last caller of the internal
set-default-branch endpoint, and both default-branch-change paths are
already covered by the metadataNotifier ChangeDefaultBranch and
PushCommits hooks. Dropped the stale row from dcs-customizations.md.

Assisted-by: Claude Code:claude-opus-5[1m]
richmahn added a commit to unfoldingWord/dcs that referenced this pull request Aug 18, 2026
Conflicts and DCS adaptations for this upstream sync:

routers/private/default_branch.go: deleted upstream by go-gitea/gitea#38964
("remove dead code SetDefaultBranch"). Accepted the deletion. The DCS
ProcessDoor43MetadataForRepo() call it held had been unreachable since
go-gitea/gitea#38089 removed the last caller of the internal
set-default-branch endpoint; both default-branch-change paths are already
covered by the metadataNotifier ChangeDefaultBranch and PushCommits hooks.
Dropped the stale row from dcs-customizations.md.

modules/gitrepo -> modules/git/gitrepo (go-gitea/gitea#38543), with
OpenRepository/UpdateRef/RemoveRef moving to modules/git and
OpenRepository gaining a leading ctx: adapted services/gitref,
services/convert2sb, services/repository/sbarchiver,
services/door43metadata and services/door43healthcheck.

Repository.RepoPath() and repo_model.RepoPath() removed
(go-gitea/gitea#38601): replaced with
gitrepo.RepoLocalPath(x.CodeStorageRepo()).

util.RemoveAll renamed to util.RemoveAllWithRetry (go-gitea/gitea#38588).

Form validation refactor (go-gitea/gitea#38832, #38873): the DCS
Door43Metadata forms did only default validation, so they now embed
middleware.FormDefaultValidator instead of defining a Validate method.

web.GetForm and cron RegisterTaskFatal became generic: updated the DCS
git-ref handlers and DCS cron task registrations.

language_stats_gogit.go deleted upstream (gogit build variant removed);
git carried the DCS every-file-type language stats into the surviving
language_stats_get.go via rename detection.

Upstream enabled the forcetypeassert linter, which surfaced 28
unchecked type assertions in pre-existing DCS manifest and langnames
parsing. Added modules/dcs/mapvalue.go with checked map accessors and
used them throughout, so malformed user-supplied manifest.yaml or
langnames data yields zero values instead of panicking.

Verified: go build ./..., go vet ./..., golangci-lint run ./... (0
issues), lint-spell, lint-templates, generate-swagger (DCS git-ref
endpoints and the new in-catalog/tag_filter params intact, no dangling
$refs).

Assisted-by: Claude Code:claude-opus-5[1m]
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Sep 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants