Skip to content

Commit f1f989b

Browse files
committed
Change the use of head request to optional (#49)
1 parent 99866fe commit f1f989b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

githttpxfer/githttpxfer.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type options struct {
8989
uploadPack bool
9090
receivePack bool
9191
dumbProto bool
92+
head bool
9293
}
9394

9495
type Option func(*options)
@@ -108,6 +109,14 @@ func DisableReceivePack() Option {
108109
func WithoutDumbProto() Option {
109110
return func(o *options) {
110111
o.dumbProto = false
112+
o.head = false
113+
}
114+
}
115+
116+
func WithoutDumbProtoExceptHead() Option {
117+
return func(o *options) {
118+
o.dumbProto = false
119+
o.head = true
111120
}
112121
}
113122

@@ -121,7 +130,7 @@ func New(gitRootPath, gitBinPath string, opts ...Option) (*GitHTTPXfer, error) {
121130
gitRootPath = cwd
122131
}
123132

124-
ghxOpts := &options{true, true, true}
133+
ghxOpts := &options{true, true, true, true}
125134

126135
for _, opt := range opts {
127136
opt(ghxOpts)
@@ -138,7 +147,6 @@ func New(gitRootPath, gitBinPath string, opts ...Option) (*GitHTTPXfer, error) {
138147
ghx.Router.Add(NewRoute(http.MethodGet, getInfoRefs, ghx.getInfoRefs))
139148

140149
if ghxOpts.dumbProto {
141-
ghx.Router.Add(NewRoute(http.MethodGet, getHead, ghx.getTextFile))
142150
ghx.Router.Add(NewRoute(http.MethodGet, getAlternates, ghx.getTextFile))
143151
ghx.Router.Add(NewRoute(http.MethodGet, getHTTPAlternates, ghx.getTextFile))
144152
ghx.Router.Add(NewRoute(http.MethodGet, getInfoPacks, ghx.getInfoPacks))
@@ -147,6 +155,11 @@ func New(gitRootPath, gitBinPath string, opts ...Option) (*GitHTTPXfer, error) {
147155
ghx.Router.Add(NewRoute(http.MethodGet, getPackFile, ghx.getPackFile))
148156
ghx.Router.Add(NewRoute(http.MethodGet, getIdxFile, ghx.getIdxFile))
149157
}
158+
159+
if ghxOpts.head {
160+
ghx.Router.Add(NewRoute(http.MethodGet, getHead, ghx.getTextFile))
161+
}
162+
150163
return ghx, nil
151164
}
152165

0 commit comments

Comments
 (0)