@@ -20,6 +20,7 @@ import (
2020 "github.com/go-git/go-git/v6/plumbing/transport"
2121 "github.com/tigrisdata/objgit/internal/auth"
2222 "github.com/tigrisdata/objgit/internal/metrics"
23+ "github.com/tigrisdata/objgit/internal/repofs"
2324)
2425
2526// ServeGitProtocol accepts connections on l until ctx is cancelled or Accept fails.
@@ -71,6 +72,12 @@ func (d *daemon) handleGitProtocol(ctx context.Context, conn net.Conn) error {
7172 "remote" , conn .RemoteAddr ().String (),
7273 )
7374
75+ ref , err := repofs .Parse (req .Pathname )
76+ if err != nil {
77+ _ , _ = pktline .WriteError (conn , err )
78+ return fmt .Errorf ("invalid repo path %q: %w" , req .Pathname , err )
79+ }
80+
7481 // ExtraParams carries e.g. "version=2"; transport.ProtocolVersion splits on ":".
7582 gitProtocol := strings .Join (req .ExtraParams , ":" )
7683
@@ -83,7 +90,7 @@ func (d *daemon) handleGitProtocol(ctx context.Context, conn net.Conn) error {
8390 start := time .Now ()
8491
8592 if d .authorize (ctx , auth.Request {
86- Repo : req . Pathname ,
93+ Repo : ref . Path () ,
8794 Operation : operationFor (req .RequestCommand ),
8895 Cred : auth.Anonymous {},
8996 Transport : "git" ,
@@ -93,7 +100,7 @@ func (d *daemon) handleGitProtocol(ctx context.Context, conn net.Conn) error {
93100 return fmt .Errorf ("access denied for %q (%s)" , req .Pathname , req .RequestCommand )
94101 }
95102
96- err : = d .serveGit (ctx , conn , r , req , gitProtocol )
103+ err = d .serveGit (ctx , conn , r , req , ref , gitProtocol )
97104 status := "ok"
98105 if err != nil {
99106 status = "error"
@@ -104,10 +111,10 @@ func (d *daemon) handleGitProtocol(ctx context.Context, conn net.Conn) error {
104111
105112// serveGit dispatches a parsed, authorized git:// request to the matching
106113// go-git transport command.
107- func (d * daemon ) serveGit (ctx context.Context , conn net.Conn , r io.ReadCloser , req packp.GitProtoRequest , gitProtocol string ) error {
114+ func (d * daemon ) serveGit (ctx context.Context , conn net.Conn , r io.ReadCloser , req packp.GitProtoRequest , ref repofs. RepoRef , gitProtocol string ) error {
108115 switch req .RequestCommand {
109116 case transport .UploadPackService :
110- st , err := d .load (req . Pathname )
117+ st , err := d .load (ctx , ref , repofs. Credential {} )
111118 if err != nil {
112119 _ , _ = pktline .WriteError (conn , fmt .Errorf ("repository %q not found" , req .Pathname ))
113120 return fmt .Errorf ("loading %q: %w" , req .Pathname , err )
@@ -117,20 +124,20 @@ func (d *daemon) serveGit(ctx context.Context, conn net.Conn, r io.ReadCloser, r
117124 })
118125
119126 case transport .UploadArchiveService :
120- st , err := d .load (req . Pathname )
127+ st , err := d .load (ctx , ref , repofs. Credential {} )
121128 if err != nil {
122129 _ , _ = pktline .WriteError (conn , fmt .Errorf ("repository %q not found" , req .Pathname ))
123130 return fmt .Errorf ("loading %q: %w" , req .Pathname , err )
124131 }
125132 return transport .UploadArchive (ctx , st , r , conn , & transport.UploadArchiveRequest {})
126133
127134 case transport .ReceivePackService :
128- st , err := d .loadOrInit (req . Pathname )
135+ st , err := d .loadOrInit (ctx , ref , repofs. Credential {} )
129136 if err != nil {
130137 _ , _ = pktline .WriteError (conn , fmt .Errorf ("cannot open repository %q" , req .Pathname ))
131138 return fmt .Errorf ("opening %q for push: %w" , req .Pathname , err )
132139 }
133- return d .receivePack (ctx , st , req . Pathname , r , conn , & transport.ReceivePackRequest {
140+ return d .receivePack (ctx , st , ref . Path () , r , conn , & transport.ReceivePackRequest {
134141 GitProtocol : gitProtocol ,
135142 })
136143
@@ -150,9 +157,9 @@ func TestDaemonPushCreatesRepo(t *testing.T) {
150157
151158 fs := memfs .New ()
152159 d := & daemon {
153- fs : fs ,
154- loader : transport . NewFilesystemLoader ( fs , false ) ,
155- authz : auth.AllowAnonymous {AllowWrite : true },
160+ sysFS : fs ,
161+ resolver : repofs. BucketResolver { Base : fs } ,
162+ authz : auth.AllowAnonymous {AllowWrite : true },
156163 }
157164
158165 ctx , cancel := context .WithCancel (context .Background ())
@@ -166,7 +173,7 @@ func TestDaemonPushCreatesRepo(t *testing.T) {
166173 srvErr := make (chan error , 1 )
167174 go func () { srvErr <- d .ServeGitProtocol (ctx , ln ) }()
168175
169- remote := "git://" + ln .Addr ().String () + "/test.git"
176+ remote := "git://" + ln .Addr ().String () + "/acme/ test.git"
170177
171178 work := t .TempDir ()
172179 runGit (t , work , "init" , "-b" , "main" )
@@ -177,8 +184,8 @@ func TestDaemonPushCreatesRepo(t *testing.T) {
177184 // The repository does not exist yet; the push must create it.
178185 runGit (t , work , "push" , remote , "main" )
179186
180- if _ , err := fs .Stat ("/test.git /config" ); err != nil {
181- t .Fatalf ("expected bare repo to be created on push, but %q is missing: %v" , "/test.git /config" , err )
187+ if _ , err := fs .Stat ("/acme/ test/config" ); err != nil {
188+ t .Fatalf ("expected bare repo to be created on push, but %q is missing: %v" , "/acme/ test/config" , err )
182189 }
183190
184191 // Round-trip: a clone must recover the pushed commit.
@@ -207,9 +214,9 @@ func TestDaemonPushDisabled(t *testing.T) {
207214
208215 fs := memfs .New ()
209216 d := & daemon {
210- fs : fs ,
211- loader : transport . NewFilesystemLoader ( fs , false ) ,
212- authz : auth.AllowAnonymous {AllowWrite : false },
217+ sysFS : fs ,
218+ resolver : repofs. BucketResolver { Base : fs } ,
219+ authz : auth.AllowAnonymous {AllowWrite : false },
213220 }
214221
215222 ctx , cancel := context .WithCancel (context .Background ())
@@ -221,7 +228,7 @@ func TestDaemonPushDisabled(t *testing.T) {
221228 }
222229 go func () { _ = d .ServeGitProtocol (ctx , ln ) }()
223230
224- remote := "git://" + ln .Addr ().String () + "/test.git"
231+ remote := "git://" + ln .Addr ().String () + "/acme/ test.git"
225232
226233 work := t .TempDir ()
227234 runGit (t , work , "init" , "-b" , "main" )
@@ -233,7 +240,7 @@ func TestDaemonPushDisabled(t *testing.T) {
233240 t .Fatalf ("expected push to be rejected when allowPush is false, got success:\n %s" , out )
234241 }
235242
236- if _ , err := fs .Stat ("/test.git /config" ); err == nil {
243+ if _ , err := fs .Stat ("/acme/ test/config" ); err == nil {
237244 t .Fatal ("repository must not be created when push is disabled" )
238245 }
239246}
@@ -251,9 +258,9 @@ func TestDaemonPushKeepsPack(t *testing.T) {
251258
252259 fs := memfs .New ()
253260 d := & daemon {
254- fs : fs ,
255- loader : transport . NewFilesystemLoader ( fs , false ) ,
256- authz : auth.AllowAnonymous {AllowWrite : true },
261+ sysFS : fs ,
262+ resolver : repofs. BucketResolver { Base : fs } ,
263+ authz : auth.AllowAnonymous {AllowWrite : true },
257264 }
258265
259266 ctx , cancel := context .WithCancel (context .Background ())
@@ -265,7 +272,7 @@ func TestDaemonPushKeepsPack(t *testing.T) {
265272 }
266273 go func () { _ = d .ServeGitProtocol (ctx , ln ) }()
267274
268- remote := "git://" + ln .Addr ().String () + "/test.git"
275+ remote := "git://" + ln .Addr ().String () + "/acme/ test.git"
269276
270277 work := t .TempDir ()
271278 runGit (t , work , "init" , "-b" , "main" )
@@ -276,7 +283,7 @@ func TestDaemonPushKeepsPack(t *testing.T) {
276283 runGit (t , work , "commit" , "-m" , "initial" ) // blob + tree + commit
277284 runGit (t , work , "push" , remote , "main" )
278285
279- assertPackedRepo (t , fs , "/test.git " )
286+ assertPackedRepo (t , fs , "/acme/ test" )
280287}
281288
282289// assertPackedRepo fails unless repoPath holds at least one packfile and no loose
0 commit comments