44package integration
55
66import (
7+ "net/http"
78 "net/url"
89 "testing"
910
@@ -18,6 +19,7 @@ import (
1819 "code.gitea.io/gitea/tests"
1920
2021 "github.com/stretchr/testify/assert"
22+ "github.com/stretchr/testify/require"
2123)
2224
2325func TestCreateNewTagProtected (t * testing.T ) {
@@ -60,6 +62,40 @@ func TestCreateNewTagProtected(t *testing.T) {
6062 })
6163 })
6264
65+ t .Run ("GitTagForce" , func (t * testing.T ) {
66+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
67+ httpContext := NewAPITestContext (t , owner .Name , repo .Name )
68+
69+ dstPath := t .TempDir ()
70+
71+ u .Path = httpContext .GitPath ()
72+ u .User = url .UserPassword (owner .Name , userPassword )
73+
74+ doGitClone (dstPath , u )(t )
75+
76+ _ , _ , err := git .NewCommand (git .DefaultContext , "tag" , "v-1.1" , "-m" , "force update" , "--force" ).RunStdString (& git.RunOpts {Dir : dstPath })
77+ require .NoError (t , err )
78+
79+ _ , _ , err = git .NewCommand (git .DefaultContext , "push" , "--tags" ).RunStdString (& git.RunOpts {Dir : dstPath })
80+ require .NoError (t , err )
81+
82+ _ , _ , err = git .NewCommand (git .DefaultContext , "tag" , "v-1.1" , "-m" , "force update v2" , "--force" ).RunStdString (& git.RunOpts {Dir : dstPath })
83+ require .NoError (t , err )
84+
85+ _ , _ , err = git .NewCommand (git .DefaultContext , "push" , "--tags" ).RunStdString (& git.RunOpts {Dir : dstPath })
86+ require .Error (t , err )
87+ assert .Contains (t , err .Error (), "the tag already exists in the remote" )
88+
89+ _ , _ , err = git .NewCommand (git .DefaultContext , "push" , "--tags" , "--force" ).RunStdString (& git.RunOpts {Dir : dstPath })
90+ require .NoError (t , err )
91+ req := NewRequestf (t , "GET" , "/%s/releases/tag/v-1.1" , repo .FullName ())
92+ resp := MakeRequest (t , req , http .StatusOK )
93+ htmlDoc := NewHTMLParser (t , resp .Body )
94+ tagsTab := htmlDoc .Find (".release-list-title" )
95+ assert .Contains (t , tagsTab .Text (), "force update v2" )
96+ })
97+ })
98+
6399 // Cleanup
64100 releases , err := db .Find [repo_model.Release ](db .DefaultContext , repo_model.FindReleasesOptions {
65101 IncludeTags : true ,
0 commit comments