Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git/gogit: modify chroot to return a new os filesystem #419

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions git/gogit/fs/osfs_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
// OS is a fs implementation based on the OS filesystem which has some
// changes in behaviour when compared to the upstream go-git/go-billy/v5/osfs:
//
// - Chroot is not supported and paths are not changed from the underlying OS fs.
// - Chroot doesn't return a chrooted filesystem but returns a new OS filesystem.
// - Relative paths are forced to descend from the working dir.
// - Symlinks don't have its targets modified, and therefore can point to locations
// outside the working dir or to non-existent paths.
Expand Down Expand Up @@ -213,8 +213,9 @@ func (fs *OS) Readlink(link string) (string, error) {
return os.Readlink(link)
}

// Chroot returns a new OS filesystem, with working directory set to path.
func (fs *OS) Chroot(path string) (billy.Filesystem, error) {
return nil, billy.ErrNotSupported
return New(path), nil
}

// Root returns the current working dir of the billy.Filesystem.
Expand Down
9 changes: 4 additions & 5 deletions git/gogit/fs/osfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,13 @@ func TestTempFile(t *testing.T) {
g.Expect(f).To(BeNil())
}

func TestUnsupportedChroot(t *testing.T) {
func TestChroot(t *testing.T) {
g := NewWithT(t)
fs := New(t.TempDir())

f, err := fs.Chroot("")
g.Expect(err).To(HaveOccurred())
g.Expect(err).To(Equal(billy.ErrNotSupported))
g.Expect(f).To(BeNil())
f, err := fs.Chroot("test")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(f).ToNot(BeNil())
}

func TestRoot(t *testing.T) {
Expand Down