@@ -22,12 +22,37 @@ import (
22
22
"code.gitea.io/gitea/modules/context"
23
23
"code.gitea.io/gitea/modules/log"
24
24
"code.gitea.io/gitea/modules/setting"
25
+
26
+ "github.com/Unknwon/com"
25
27
)
26
28
29
+ func composeGoGetImport (owner , repo , sub string ) string {
30
+ return path .Join (setting .Domain , setting .AppSubURL , owner , repo , sub )
31
+ }
32
+
33
+ // earlyResponseForGoGetMeta responses appropriate go-get meta with status 200
34
+ // if user does not have actual access to the requested repository,
35
+ // or the owner or repository does not exist at all.
36
+ // This is particular a workaround for "go get" command which does not respect
37
+ // .netrc file.
38
+ func earlyResponseForGoGetMeta (ctx * context.Context , username , reponame , subpath string ) {
39
+ ctx .PlainText (200 , []byte (com .Expand (`<meta name="go-import" content="{GoGetImport} git {CloneLink}">` ,
40
+ map [string ]string {
41
+ "GoGetImport" : composeGoGetImport (username , reponame , subpath ),
42
+ "CloneLink" : models .ComposeHTTPSCloneURL (username , reponame ),
43
+ })))
44
+ }
45
+
27
46
// HTTP implmentation git smart HTTP protocol
28
47
func HTTP (ctx * context.Context ) {
29
48
username := ctx .Params (":username" )
30
49
reponame := strings .TrimSuffix (ctx .Params (":reponame" ), ".git" )
50
+ subpath := ctx .Params ("*" )
51
+
52
+ if ctx .Query ("go-get" ) == "1" {
53
+ earlyResponseForGoGetMeta (ctx , username , reponame , subpath )
54
+ return
55
+ }
31
56
32
57
var isPull bool
33
58
service := ctx .Query ("service" )
0 commit comments