Skip to content

Commit 46fe16f

Browse files
committed
fix: allow direct commits for unprotected files when branch-wide push is restricted
1 parent 2eb7b3c commit 46fe16f

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

services/context/repo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ func PrepareCommitFormOptions(ctx *Context, doer *user_model.User, targetRepo *r
173173
protectedBranch.Repo = targetRepo
174174
canPushWithProtection = protectedBranch.CanUserPush(ctx, doer)
175175
protectionRequireSigned = protectedBranch.RequireSignedCommits
176+
// If the user can't push branch-wide but the specific file being edited
177+
// matches an unprotected file pattern, direct commit is still allowed.
178+
if !canPushWithProtection && ctx.Repo.TreePath != "" {
179+
globUnprotected := protectedBranch.GetUnprotectedFilePatterns()
180+
if protectedBranch.IsUnprotectedFile(globUnprotected, ctx.Repo.TreePath) {
181+
canPushWithProtection = true
182+
}
183+
}
176184
}
177185

178186
targetGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, targetRepo)

0 commit comments

Comments
 (0)