@@ -10,6 +10,7 @@ import (
10
10
"path"
11
11
"path/filepath"
12
12
"strconv"
13
+ "strings"
13
14
"time"
14
15
15
16
"github.com/charmbracelet/soft-serve/git"
@@ -24,10 +25,6 @@ import (
24
25
"github.com/charmbracelet/soft-serve/pkg/webhook"
25
26
)
26
27
27
- func (d * Backend ) reposPath () string {
28
- return filepath .Join (d .cfg .DataPath , "repos" )
29
- }
30
-
31
28
// CreateRepository creates a new repository.
32
29
//
33
30
// It implements backend.Backend.
@@ -37,8 +34,7 @@ func (d *Backend) CreateRepository(ctx context.Context, name string, user proto.
37
34
return nil , err
38
35
}
39
36
40
- repo := name + ".git"
41
- rp := filepath .Join (d .reposPath (), repo )
37
+ rp := filepath .Join (d .repoPath (name ))
42
38
43
39
var userID int64
44
40
if user != nil {
@@ -78,7 +74,7 @@ func (d *Backend) CreateRepository(ctx context.Context, name string, user proto.
78
74
}
79
75
}
80
76
81
- return hooks .GenerateHooks (ctx , d .cfg , repo )
77
+ return hooks .GenerateHooks (ctx , d .cfg , name )
82
78
}); err != nil {
83
79
d .logger .Debug ("failed to create repository in database" , "err" , err )
84
80
err = db .WrapError (err )
@@ -100,8 +96,7 @@ func (d *Backend) ImportRepository(_ context.Context, name string, user proto.Us
100
96
return nil , err
101
97
}
102
98
103
- repo := name + ".git"
104
- rp := filepath .Join (d .reposPath (), repo )
99
+ rp := filepath .Join (d .repoPath (name ))
105
100
106
101
tid := "import:" + name
107
102
if d .manager .Exists (tid ) {
@@ -217,8 +212,7 @@ func (d *Backend) ImportRepository(_ context.Context, name string, user proto.Us
217
212
// It implements backend.Backend.
218
213
func (d * Backend ) DeleteRepository (ctx context.Context , name string ) error {
219
214
name = utils .SanitizeRepo (name )
220
- repo := name + ".git"
221
- rp := filepath .Join (d .reposPath (), repo )
215
+ rp := filepath .Join (d .repoPath (name ))
222
216
223
217
user := proto .UserFromContext (ctx )
224
218
r , err := d .Repository (ctx , name )
@@ -330,10 +324,8 @@ func (d *Backend) RenameRepository(ctx context.Context, oldName string, newName
330
324
return nil
331
325
}
332
326
333
- oldRepo := oldName + ".git"
334
- newRepo := newName + ".git"
335
- op := filepath .Join (d .reposPath (), oldRepo )
336
- np := filepath .Join (d .reposPath (), newRepo )
327
+ op := filepath .Join (d .repoPath (oldName ))
328
+ np := filepath .Join (d .repoPath (newName ))
337
329
if _ , err := os .Stat (op ); err != nil {
338
330
return proto .ErrRepoNotFound
339
331
}
@@ -389,7 +381,7 @@ func (d *Backend) Repositories(ctx context.Context) ([]proto.Repository, error)
389
381
for _ , m := range ms {
390
382
r := & repo {
391
383
name : m .Name ,
392
- path : filepath .Join (d .reposPath (), m .Name + ".git" ),
384
+ path : filepath .Join (d .repoPath ( m .Name ) ),
393
385
repo : m ,
394
386
}
395
387
@@ -418,7 +410,7 @@ func (d *Backend) Repository(ctx context.Context, name string) (proto.Repository
418
410
return r , nil
419
411
}
420
412
421
- rp := filepath .Join (d .reposPath (), name + ".git" )
413
+ rp := filepath .Join (d .repoPath ( name ) )
422
414
if _ , err := os .Stat (rp ); err != nil {
423
415
if ! errors .Is (err , fs .ErrNotExist ) {
424
416
d .logger .Errorf ("failed to stat repository path: %v" , err )
@@ -552,7 +544,7 @@ func (d *Backend) SetHidden(ctx context.Context, name string, hidden bool) error
552
544
// It implements backend.Backend.
553
545
func (d * Backend ) SetDescription (ctx context.Context , name string , desc string ) error {
554
546
name = utils .SanitizeRepo (name )
555
- rp := filepath .Join (d .reposPath (), name + ".git" )
547
+ rp := filepath .Join (d .repoPath ( name ) )
556
548
557
549
// Delete cache
558
550
d .cache .Delete (name )
@@ -572,7 +564,7 @@ func (d *Backend) SetDescription(ctx context.Context, name string, desc string)
572
564
// It implements backend.Backend.
573
565
func (d * Backend ) SetPrivate (ctx context.Context , name string , private bool ) error {
574
566
name = utils .SanitizeRepo (name )
575
- rp := filepath .Join (d .reposPath (), name + ".git" )
567
+ rp := filepath .Join (d .repoPath ( name ) )
576
568
577
569
// Delete cache
578
570
d .cache .Delete (name )
@@ -636,6 +628,13 @@ func (d *Backend) SetProjectName(ctx context.Context, repo string, name string)
636
628
)
637
629
}
638
630
631
+ // repoPath returns the path to a repository.
632
+ func (d * Backend ) repoPath (name string ) string {
633
+ name = utils .SanitizeRepo (name )
634
+ rn := strings .ReplaceAll (name , "/" , string (os .PathSeparator ))
635
+ return filepath .Join (filepath .Join (d .cfg .DataPath , "repos" ), rn + ".git" )
636
+ }
637
+
639
638
var _ proto.Repository = (* repo )(nil )
640
639
641
640
// repo is a Git repository with metadata stored in a SQLite database.
0 commit comments