4
4
package integration
5
5
6
6
import (
7
+ "net/http"
7
8
"net/url"
8
9
"testing"
9
10
@@ -18,6 +19,7 @@ import (
18
19
"code.gitea.io/gitea/tests"
19
20
20
21
"github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
21
23
)
22
24
23
25
func TestCreateNewTagProtected (t * testing.T ) {
@@ -60,6 +62,40 @@ func TestCreateNewTagProtected(t *testing.T) {
60
62
})
61
63
})
62
64
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
+
63
99
// Cleanup
64
100
releases , err := db .Find [repo_model.Release ](db .DefaultContext , repo_model.FindReleasesOptions {
65
101
IncludeTags : true ,
0 commit comments