Skip to content

Commit dc3adbb

Browse files
committed
git: Make osfs.BoundOS the default osfs. Fixes #1155
The BoundOS further aligns go-git with the upstream behaviour, removing suprises that generally catch go-git users off-guard. For more information refer to go-billy's docs: https://github.com/go-git/go-billy/blob/69f6dc8f11964f3aafa2a7a0be6db030ad43ecf4/osfs/os_bound.go#L32-L42 Signed-off-by: Paulo Gomes <[email protected]>
1 parent 299d369 commit dc3adbb

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module github.com/go-git/go-git/v5
33
// go-git supports the last 3 stable Go versions.
44
go 1.20
55

6+
replace github.com/go-git/go-billy/v5 => github.com/go-git/go-billy/v5 v5.0.0-20240804231525-dc481f5289ba
7+
68
require (
79
dario.cat/mergo v1.0.0
810
github.com/ProtonMail/go-crypto v1.0.0

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
2929
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
3030
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
3131
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
32-
github.com/go-git/go-billy/v5 v5.5.1-0.20240427054813-8453aa90c6ec h1:JtjPVUU/+C1OaEXG+ojNfspw7t7Y30jiyr6zsXA8Eco=
33-
github.com/go-git/go-billy/v5 v5.5.1-0.20240427054813-8453aa90c6ec/go.mod h1:bmsuIkj+yaSISZdLRNCLRaSiWnwDatBN1b62vLkXn24=
32+
github.com/go-git/go-billy/v5 v5.0.0-20240804231525-dc481f5289ba h1:ri3xJXEvkWt6LDkX24uy+MCmc4L9O/ZotjcVzZC+7Ug=
33+
github.com/go-git/go-billy/v5 v5.0.0-20240804231525-dc481f5289ba/go.mod h1:j9ZRVN9a7j6LUbqf39FthSLGwo1+mGB4CN8bmUxdYVo=
3434
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
3535
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
3636
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
@@ -49,7 +49,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
4949
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
5050
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
5151
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
52-
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
5352
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
5453
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
5554
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
198198
// faster to use a local storage layer to get the commits
199199
// to ignore, when calculating the object revlist.
200200
localStorer := filesystem.NewStorage(
201-
osfs.New(o.RemoteURL), cache.NewObjectLRUDefault())
201+
osfs.New(o.RemoteURL, osfs.WithBoundOS()), cache.NewObjectLRUDefault())
202202
hashesToPush, err = revlist.ObjectsWithStorageForIgnores(
203203
r.s, localStorer, objects, haves)
204204
} else {

repository.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ func PlainInitWithOptions(path string, opts *PlainInitOptions) (*Repository, err
256256
var wt, dot billy.Filesystem
257257

258258
if opts.Bare {
259-
dot = osfs.New(path)
259+
dot = osfs.New(path, osfs.WithBoundOS())
260260
} else {
261-
wt = osfs.New(path)
261+
wt = osfs.New(path, osfs.WithBoundOS())
262262
dot, _ = wt.Chroot(GitDirName)
263263
}
264264

@@ -344,15 +344,15 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
344344
var fs billy.Filesystem
345345
var fi os.FileInfo
346346
for {
347-
fs = osfs.New(path)
347+
fs = osfs.New(path, osfs.WithBoundOS())
348348

349349
pathinfo, err := fs.Stat("/")
350350
if !os.IsNotExist(err) {
351351
if pathinfo == nil {
352352
return nil, nil, err
353353
}
354354
if !pathinfo.IsDir() && detect {
355-
fs = osfs.New(filepath.Dir(path))
355+
fs = osfs.New(filepath.Dir(path), osfs.WithBoundOS())
356356
}
357357
}
358358

@@ -412,10 +412,10 @@ func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (bfs billy.Files
412412
gitdir := strings.Split(line[len(prefix):], "\n")[0]
413413
gitdir = strings.TrimSpace(gitdir)
414414
if filepath.IsAbs(gitdir) {
415-
return osfs.New(gitdir), nil
415+
return osfs.New(gitdir, osfs.WithBoundOS()), nil
416416
}
417417

418-
return osfs.New(fs.Join(path, gitdir)), nil
418+
return osfs.New(fs.Join(path, gitdir), osfs.WithBoundOS()), nil
419419
}
420420

421421
func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err error) {
@@ -434,9 +434,9 @@ func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err
434434
if len(b) > 0 {
435435
path := strings.TrimSpace(string(b))
436436
if filepath.IsAbs(path) {
437-
commonDir = osfs.New(path)
437+
commonDir = osfs.New(path, osfs.WithBoundOS())
438438
} else {
439-
commonDir = osfs.New(filepath.Join(fs.Root(), path))
439+
commonDir = osfs.New(filepath.Join(fs.Root(), path), osfs.WithBoundOS())
440440
}
441441
if _, err := commonDir.Stat(""); err != nil {
442442
if os.IsNotExist(err) {

0 commit comments

Comments
 (0)