Skip to content

Commit

Permalink
git: Make osfs.BoundOS the default osfs. Fixes go-git#1155
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pjbgf committed Aug 9, 2024
1 parent a47abe9 commit 916ca65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module github.com/go-git/go-git/v5
// go-git supports the last 3 stable Go versions.
go 1.20

replace github.com/go-git/go-billy/v5 => github.com/go-git/go-billy/v5 v5.0.0-20240804231525-dc481f5289ba

require (
dario.cat/mergo v1.0.0
github.com/ProtonMail/go-crypto v1.0.0
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
github.com/go-git/go-billy/v5 v5.5.1-0.20240427054813-8453aa90c6ec h1:JtjPVUU/+C1OaEXG+ojNfspw7t7Y30jiyr6zsXA8Eco=
github.com/go-git/go-billy/v5 v5.5.1-0.20240427054813-8453aa90c6ec/go.mod h1:bmsuIkj+yaSISZdLRNCLRaSiWnwDatBN1b62vLkXn24=
github.com/go-git/go-billy/v5 v5.0.0-20240804231525-dc481f5289ba h1:ri3xJXEvkWt6LDkX24uy+MCmc4L9O/ZotjcVzZC+7Ug=
github.com/go-git/go-billy/v5 v5.0.0-20240804231525-dc481f5289ba/go.mod h1:j9ZRVN9a7j6LUbqf39FthSLGwo1+mGB4CN8bmUxdYVo=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
Expand All @@ -49,7 +49,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
Expand Down
2 changes: 1 addition & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
// faster to use a local storage layer to get the commits
// to ignore, when calculating the object revlist.
localStorer := filesystem.NewStorage(
osfs.New(o.RemoteURL), cache.NewObjectLRUDefault())
osfs.New(o.RemoteURL, osfs.WithBoundOS()), cache.NewObjectLRUDefault())
hashesToPush, err = revlist.ObjectsWithStorageForIgnores(
r.s, localStorer, objects, haves)
} else {
Expand Down
16 changes: 8 additions & 8 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ func PlainInitWithOptions(path string, opts *PlainInitOptions) (*Repository, err
var wt, dot billy.Filesystem

if opts.Bare {
dot = osfs.New(path)
dot = osfs.New(path, osfs.WithBoundOS())
} else {
wt = osfs.New(path)
wt = osfs.New(path, osfs.WithBoundOS())
dot, _ = wt.Chroot(GitDirName)
}

Expand Down Expand Up @@ -344,15 +344,15 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
var fs billy.Filesystem
var fi os.FileInfo
for {
fs = osfs.New(path)
fs = osfs.New(path, osfs.WithBoundOS())

pathinfo, err := fs.Stat("/")
if !os.IsNotExist(err) {
if pathinfo == nil {
return nil, nil, err
}
if !pathinfo.IsDir() && detect {
fs = osfs.New(filepath.Dir(path))
fs = osfs.New(filepath.Dir(path), osfs.WithBoundOS())
}
}

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

return osfs.New(fs.Join(path, gitdir)), nil
return osfs.New(fs.Join(path, gitdir), osfs.WithBoundOS()), nil
}

func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err error) {
Expand All @@ -434,9 +434,9 @@ func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err
if len(b) > 0 {
path := strings.TrimSpace(string(b))
if filepath.IsAbs(path) {
commonDir = osfs.New(path)
commonDir = osfs.New(path, osfs.WithBoundOS())
} else {
commonDir = osfs.New(filepath.Join(fs.Root(), path))
commonDir = osfs.New(filepath.Join(fs.Root(), path), osfs.WithBoundOS())
}
if _, err := commonDir.Stat(""); err != nil {
if os.IsNotExist(err) {
Expand Down

0 comments on commit 916ca65

Please sign in to comment.