summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorGusted <postmaster@gusted.xyz>2024-09-12 15:21:04 +0200
committerGusted <postmaster@gusted.xyz>2024-10-02 20:50:06 +0200
commit84e77c41fa1c7f244260691bd6e2a2e40c11f45f (patch)
tree2e8a3c17704d34ff866dfb7ac09cff6febc00ed0 /cmd
parentMerge pull request 'ci: move composite workflow location' (#5421) from fnetx/... (diff)
downloadforgejo-84e77c41fa1c7f244260691bd6e2a2e40c11f45f.tar.xz
forgejo-84e77c41fa1c7f244260691bd6e2a2e40c11f45f.zip
[FEAT] Don't allow modification to internal reference
- This a port of https://github.com/go-gitea/gitea/pull/31931 in a behavior-sense. None of the code was actually ported. - Follow up for #2834, now also don't allow modification. - Integration test added. - Unit test modified.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hook.go3
-rw-r--r--cmd/hook_test.go9
2 files changed, 10 insertions, 2 deletions
diff --git a/cmd/hook.go b/cmd/hook.go
index edab611972..93dfd9d648 100644
--- a/cmd/hook.go
+++ b/cmd/hook.go
@@ -322,7 +322,8 @@ func runHookUpdate(c *cli.Context) error {
return fail(ctx, fmt.Sprintf("The deletion of %s is skipped as it's an internal reference.", refFullName), "")
}
- return nil
+ // If the new comment isn't empty it means modification.
+ return fail(ctx, fmt.Sprintf("The modification of %s is skipped as it's an internal reference.", refFullName), "")
}
func runHookPostReceive(c *cli.Context) error {
diff --git a/cmd/hook_test.go b/cmd/hook_test.go
index 514eb917e1..1f0ee7087b 100644
--- a/cmd/hook_test.go
+++ b/cmd/hook_test.go
@@ -180,8 +180,15 @@ func TestRunHookUpdate(t *testing.T) {
})
t.Run("Update of internal reference", func(t *testing.T) {
+ defer test.MockVariableValue(&cli.OsExiter, func(code int) {})()
+ defer test.MockVariableValue(&setting.IsProd, false)()
+ finish := captureOutput(t, os.Stderr)
+
err := app.Run([]string{"./forgejo", "update", "refs/pull/1/head", "0a51ae26bc73c47e2f754560c40904cf14ed51a9", "0000000000000000000000000000000000000001"})
- require.NoError(t, err)
+ out := finish()
+ require.Error(t, err)
+
+ assert.Contains(t, out, "The modification of refs/pull/1/head is skipped as it's an internal reference.")
})
t.Run("Removal of branch", func(t *testing.T) {