aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--repository.go2
-rw-r--r--repository_test.go2
-rw-r--r--submodule.go2
-rw-r--r--submodule_test.go2
-rw-r--r--worktree.go22
-rw-r--r--worktree_commit.go2
-rw-r--r--worktree_commit_test.go8
-rw-r--r--worktree_status.go20
-rw-r--r--worktree_test.go120
9 files changed, 91 insertions, 89 deletions
diff --git a/repository.go b/repository.go
index b80f8d9..00ffaf7 100644
--- a/repository.go
+++ b/repository.go
@@ -844,7 +844,7 @@ func (r *Repository) Worktree() (*Worktree, error) {
return nil, ErrIsBareRepository
}
- return &Worktree{r: r, fs: r.wt}, nil
+ return &Worktree{r: r, Filesystem: r.wt}, nil
}
// ResolveRevision resolves revision to corresponding hash.
diff --git a/repository_test.go b/repository_test.go
index 7f984f6..558149b 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -1138,7 +1138,7 @@ func (s *RepositorySuite) TestWorktree(c *C) {
r, _ := Init(memory.NewStorage(), def)
w, err := r.Worktree()
c.Assert(err, IsNil)
- c.Assert(w.fs, Equals, def)
+ c.Assert(w.Filesystem, Equals, def)
}
func (s *RepositorySuite) TestWorktreeBare(c *C) {
diff --git a/submodule.go b/submodule.go
index ac027c2..fbaddfd 100644
--- a/submodule.go
+++ b/submodule.go
@@ -115,7 +115,7 @@ func (s *Submodule) Repository() (*Repository, error) {
}
var worktree billy.Filesystem
- if worktree, err = s.w.fs.Chroot(s.c.Path); err != nil {
+ if worktree, err = s.w.Filesystem.Chroot(s.c.Path); err != nil {
return nil, err
}
diff --git a/submodule_test.go b/submodule_test.go
index dd797c5..e4f3013 100644
--- a/submodule_test.go
+++ b/submodule_test.go
@@ -128,7 +128,7 @@ func (s *SubmoduleSuite) TestUpdateWithRecursion(c *C) {
c.Assert(err, IsNil)
- fs := s.Worktree.fs
+ fs := s.Worktree.Filesystem
_, err = fs.Stat(fs.Join("itself", "basic", "LICENSE"))
c.Assert(err, IsNil)
}
diff --git a/worktree.go b/worktree.go
index 01f8b01..4e4d544 100644
--- a/worktree.go
+++ b/worktree.go
@@ -30,8 +30,10 @@ var (
// Worktree represents a git worktree.
type Worktree struct {
- r *Repository
- fs billy.Filesystem
+ // Filesystem underlying filesystem.
+ Filesystem billy.Filesystem
+
+ r *Repository
}
// Pull incorporates changes from a remote repository into the current branch.
@@ -398,13 +400,13 @@ func (w *Worktree) checkoutChangeSubmodule(name string,
return err
}
- if err := w.fs.MkdirAll(name, mode); err != nil {
+ if err := w.Filesystem.MkdirAll(name, mode); err != nil {
return err
}
return w.addIndexFromTreeEntry(name, e, idx)
case merkletrie.Delete:
- if err := rmFileAndDirIfEmpty(w.fs, name); err != nil {
+ if err := rmFileAndDirIfEmpty(w.Filesystem, name); err != nil {
return err
}
@@ -428,7 +430,7 @@ func (w *Worktree) checkoutChangeRegularFile(name string,
// to apply perm changes the file is deleted, billy doesn't implement
// chmod
- if err := w.fs.Remove(name); err != nil {
+ if err := w.Filesystem.Remove(name); err != nil {
return err
}
@@ -445,7 +447,7 @@ func (w *Worktree) checkoutChangeRegularFile(name string,
return w.addIndexFromFile(name, e.Hash, idx)
case merkletrie.Delete:
- if err := rmFileAndDirIfEmpty(w.fs, name); err != nil {
+ if err := rmFileAndDirIfEmpty(w.Filesystem, name); err != nil {
return err
}
@@ -472,7 +474,7 @@ func (w *Worktree) checkoutFile(f *object.File) (err error) {
defer ioutil.CheckClose(from, &err)
- to, err := w.fs.OpenFile(f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode.Perm())
+ to, err := w.Filesystem.OpenFile(f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode.Perm())
if err != nil {
return
}
@@ -496,7 +498,7 @@ func (w *Worktree) checkoutFileSymlink(f *object.File) (err error) {
return
}
- err = w.fs.Symlink(string(bytes), f.Name)
+ err = w.Filesystem.Symlink(string(bytes), f.Name)
return
}
@@ -511,7 +513,7 @@ func (w *Worktree) addIndexFromTreeEntry(name string, f *object.TreeEntry, idx *
}
func (w *Worktree) addIndexFromFile(name string, h plumbing.Hash, idx *index.Index) error {
- fi, err := w.fs.Lstat(name)
+ fi, err := w.Filesystem.Lstat(name)
if err != nil {
return err
}
@@ -620,7 +622,7 @@ func (w *Worktree) newSubmodule(fromModules, fromConfig *config.Submodule) *Subm
}
func (w *Worktree) readGitmodulesFile() (*config.Modules, error) {
- f, err := w.fs.Open(gitmodulesFile)
+ f, err := w.Filesystem.Open(gitmodulesFile)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
diff --git a/worktree_commit.go b/worktree_commit.go
index 02a5d03..e5d0a11 100644
--- a/worktree_commit.go
+++ b/worktree_commit.go
@@ -32,7 +32,7 @@ func (w *Worktree) Commit(msg string, opts *CommitOptions) (plumbing.Hash, error
}
h := &buildTreeHelper{
- fs: w.fs,
+ fs: w.Filesystem,
s: w.r.Storer,
}
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index 8f3b7b0..f6744bc 100644
--- a/worktree_commit_test.go
+++ b/worktree_commit_test.go
@@ -54,8 +54,8 @@ func (s *WorktreeSuite) TestCommitParent(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
@@ -78,8 +78,8 @@ func (s *WorktreeSuite) TestCommitAll(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
diff --git a/worktree_status.go b/worktree_status.go
index a662516..9b0773e 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -116,7 +116,7 @@ func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) {
return nil, err
}
- to := filesystem.NewRootNode(w.fs, submodules)
+ to := filesystem.NewRootNode(w.Filesystem, submodules)
res, err := merkletrie.DiffTree(from, to, diffTreeIsEquals)
if err == nil {
res = w.excludeIgnoredChanges(res)
@@ -125,7 +125,7 @@ func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) {
}
func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
- patterns, err := gitignore.ReadPatterns(w.fs, nil)
+ patterns, err := gitignore.ReadPatterns(w.Filesystem, nil)
if err != nil || len(patterns) == 0 {
return changes
}
@@ -251,7 +251,7 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) {
}
func (w *Worktree) copyFileToStorage(path string) (hash plumbing.Hash, err error) {
- fi, err := w.fs.Lstat(path)
+ fi, err := w.Filesystem.Lstat(path)
if err != nil {
return plumbing.ZeroHash, err
}
@@ -281,7 +281,7 @@ func (w *Worktree) copyFileToStorage(path string) (hash plumbing.Hash, err error
}
func (w *Worktree) fillEncodedObjectFromFile(dst io.Writer, path string, fi os.FileInfo) (err error) {
- src, err := w.fs.Open(path)
+ src, err := w.Filesystem.Open(path)
if err != nil {
return err
}
@@ -296,7 +296,7 @@ func (w *Worktree) fillEncodedObjectFromFile(dst io.Writer, path string, fi os.F
}
func (w *Worktree) fillEncodedObjectFromSymlink(dst io.Writer, path string, fi os.FileInfo) error {
- target, err := w.fs.Readlink(path)
+ target, err := w.Filesystem.Readlink(path)
if err != nil {
return err
}
@@ -337,7 +337,7 @@ func (w *Worktree) doAddFileToIndex(idx *index.Index, filename string, h plumbin
}
func (w *Worktree) doUpdateFileToIndex(e *index.Entry, filename string, h plumbing.Hash) error {
- info, err := w.fs.Lstat(filename)
+ info, err := w.Filesystem.Lstat(filename)
if err != nil {
return err
}
@@ -382,7 +382,7 @@ func (w *Worktree) deleteFromIndex(path string) (plumbing.Hash, error) {
}
func (w *Worktree) deleteFromFilesystem(path string) error {
- err := w.fs.Remove(path)
+ err := w.Filesystem.Remove(path)
if os.IsNotExist(err) {
return nil
}
@@ -393,11 +393,11 @@ func (w *Worktree) deleteFromFilesystem(path string) error {
// Move moves or rename a file in the worktree and the index, directories are
// not supported.
func (w *Worktree) Move(from, to string) (plumbing.Hash, error) {
- if _, err := w.fs.Lstat(from); err != nil {
+ if _, err := w.Filesystem.Lstat(from); err != nil {
return plumbing.ZeroHash, err
}
- if _, err := w.fs.Lstat(to); err == nil {
+ if _, err := w.Filesystem.Lstat(to); err == nil {
return plumbing.ZeroHash, ErrDestinationExists
}
@@ -406,7 +406,7 @@ func (w *Worktree) Move(from, to string) (plumbing.Hash, error) {
return plumbing.ZeroHash, err
}
- if err := w.fs.Rename(from, to); err != nil {
+ if err := w.Filesystem.Rename(from, to); err != nil {
return hash, err
}
diff --git a/worktree_test.go b/worktree_test.go
index c565e29..10774a4 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -252,8 +252,8 @@ func (s *RepositorySuite) TestPullAdd(c *C) {
func (s *WorktreeSuite) TestCheckout(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
@@ -285,12 +285,12 @@ func (s *WorktreeSuite) TestCheckoutSymlink(c *C) {
w, err := r.Worktree()
c.Assert(err, IsNil)
- w.fs.Symlink("not-exists", "bar")
+ w.Filesystem.Symlink("not-exists", "bar")
w.Add("bar")
w.Commit("foo", &CommitOptions{Author: defaultSignature()})
r.Storer.SetIndex(&index.Index{Version: 2})
- w.fs = osfs.New(filepath.Join(dir, "worktree-empty"))
+ w.Filesystem = osfs.New(filepath.Join(dir, "worktree-empty"))
err = w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
@@ -299,7 +299,7 @@ func (s *WorktreeSuite) TestCheckoutSymlink(c *C) {
c.Assert(err, IsNil)
c.Assert(status.IsClean(), Equals, true)
- target, err := w.fs.Readlink("bar")
+ target, err := w.Filesystem.Readlink("bar")
c.Assert(target, Equals, "not-exists")
c.Assert(err, IsNil)
}
@@ -340,8 +340,8 @@ func (s *WorktreeSuite) TestCheckoutSubmoduleInitialized(c *C) {
func (s *WorktreeSuite) TestCheckoutIndexMem(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
@@ -370,8 +370,8 @@ func (s *WorktreeSuite) TestCheckoutIndexOS(c *C) {
fs := osfs.New(filepath.Join(dir, "worktree"))
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err = w.Checkout(&CheckoutOptions{})
@@ -395,8 +395,8 @@ func (s *WorktreeSuite) TestCheckoutIndexOS(c *C) {
func (s *WorktreeSuite) TestCheckoutBranch(c *C) {
w := &Worktree{
- r: s.Repository,
- fs: memfs.New(),
+ r: s.Repository,
+ Filesystem: memfs.New(),
}
err := w.Checkout(&CheckoutOptions{
@@ -415,8 +415,8 @@ func (s *WorktreeSuite) TestCheckoutBranch(c *C) {
func (s *WorktreeSuite) TestCheckoutCreateWithHash(c *C) {
w := &Worktree{
- r: s.Repository,
- fs: memfs.New(),
+ r: s.Repository,
+ Filesystem: memfs.New(),
}
err := w.Checkout(&CheckoutOptions{
@@ -438,8 +438,8 @@ func (s *WorktreeSuite) TestCheckoutCreateWithHash(c *C) {
func (s *WorktreeSuite) TestCheckoutCreate(c *C) {
w := &Worktree{
- r: s.Repository,
- fs: memfs.New(),
+ r: s.Repository,
+ Filesystem: memfs.New(),
}
err := w.Checkout(&CheckoutOptions{
@@ -460,8 +460,8 @@ func (s *WorktreeSuite) TestCheckoutCreate(c *C) {
func (s *WorktreeSuite) TestCheckoutBranchAndHash(c *C) {
w := &Worktree{
- r: s.Repository,
- fs: memfs.New(),
+ r: s.Repository,
+ Filesystem: memfs.New(),
}
err := w.Checkout(&CheckoutOptions{
@@ -474,8 +474,8 @@ func (s *WorktreeSuite) TestCheckoutBranchAndHash(c *C) {
func (s *WorktreeSuite) TestCheckoutCreateMissingBranch(c *C) {
w := &Worktree{
- r: s.Repository,
- fs: memfs.New(),
+ r: s.Repository,
+ Filesystem: memfs.New(),
}
err := w.Checkout(&CheckoutOptions{
@@ -557,8 +557,8 @@ func (s *WorktreeSuite) testCheckoutBisect(c *C, url string) {
func (s *WorktreeSuite) TestCheckoutWithGitignore(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
@@ -586,8 +586,8 @@ func (s *WorktreeSuite) TestCheckoutWithGitignore(c *C) {
func (s *WorktreeSuite) TestStatus(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
status, err := w.Status()
@@ -635,8 +635,8 @@ func (s *WorktreeSuite) TestStatusEmptyDirty(c *C) {
func (s *WorktreeSuite) TestReset(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
commit := plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9")
@@ -659,8 +659,8 @@ func (s *WorktreeSuite) TestReset(c *C) {
func (s *WorktreeSuite) TestResetMerge(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
commit := plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9")
@@ -686,8 +686,8 @@ func (s *WorktreeSuite) TestResetMerge(c *C) {
func (s *WorktreeSuite) TestResetHard(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
commit := plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9")
@@ -713,8 +713,8 @@ func (s *WorktreeSuite) TestResetHard(c *C) {
func (s *WorktreeSuite) TestStatusAfterCheckout(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -732,8 +732,8 @@ func (s *WorktreeSuite) TestStatusModified(c *C) {
fs := osfs.New(filepath.Join(dir, "worktree"))
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err = w.Checkout(&CheckoutOptions{})
@@ -755,8 +755,8 @@ func (s *WorktreeSuite) TestStatusModified(c *C) {
func (s *WorktreeSuite) TestStatusIgnored(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
w.Checkout(&CheckoutOptions{})
@@ -802,14 +802,14 @@ func (s *WorktreeSuite) TestStatusIgnored(c *C) {
func (s *WorktreeSuite) TestStatusUntracked(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
c.Assert(err, IsNil)
- f, err := w.fs.Create("foo")
+ f, err := w.Filesystem.Create("foo")
c.Assert(err, IsNil)
c.Assert(f.Close(), IsNil)
@@ -825,8 +825,8 @@ func (s *WorktreeSuite) TestStatusDeleted(c *C) {
fs := osfs.New(filepath.Join(dir, "worktree"))
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err = w.Checkout(&CheckoutOptions{})
@@ -872,8 +872,8 @@ func (s *WorktreeSuite) TestSubmodules(c *C) {
func (s *WorktreeSuite) TestAddUntracked(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -883,7 +883,7 @@ func (s *WorktreeSuite) TestAddUntracked(c *C) {
c.Assert(err, IsNil)
c.Assert(idx.Entries, HasLen, 9)
- err = util.WriteFile(w.fs, "foo", []byte("FOO"), 0755)
+ err = util.WriteFile(w.Filesystem, "foo", []byte("FOO"), 0755)
c.Assert(err, IsNil)
hash, err := w.Add("foo")
@@ -916,8 +916,8 @@ func (s *WorktreeSuite) TestAddUntracked(c *C) {
func (s *WorktreeSuite) TestAddModified(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -927,7 +927,7 @@ func (s *WorktreeSuite) TestAddModified(c *C) {
c.Assert(err, IsNil)
c.Assert(idx.Entries, HasLen, 9)
- err = util.WriteFile(w.fs, "LICENSE", []byte("FOO"), 0644)
+ err = util.WriteFile(w.Filesystem, "LICENSE", []byte("FOO"), 0644)
c.Assert(err, IsNil)
hash, err := w.Add("LICENSE")
@@ -955,8 +955,8 @@ func (s *WorktreeSuite) TestAddModified(c *C) {
func (s *WorktreeSuite) TestAddUnmodified(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -998,8 +998,8 @@ func (s *WorktreeSuite) TestAddSymlink(c *C) {
func (s *WorktreeSuite) TestRemove(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -1018,8 +1018,8 @@ func (s *WorktreeSuite) TestRemove(c *C) {
func (s *WorktreeSuite) TestRemoveNotExistentEntry(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -1033,8 +1033,8 @@ func (s *WorktreeSuite) TestRemoveNotExistentEntry(c *C) {
func (s *WorktreeSuite) TestRemoveDeletedFromWorktree(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -1056,8 +1056,8 @@ func (s *WorktreeSuite) TestRemoveDeletedFromWorktree(c *C) {
func (s *WorktreeSuite) TestMove(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -1078,8 +1078,8 @@ func (s *WorktreeSuite) TestMove(c *C) {
func (s *WorktreeSuite) TestMoveNotExistentEntry(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})
@@ -1093,8 +1093,8 @@ func (s *WorktreeSuite) TestMoveNotExistentEntry(c *C) {
func (s *WorktreeSuite) TestMoveToExistent(c *C) {
fs := memfs.New()
w := &Worktree{
- r: s.Repository,
- fs: fs,
+ r: s.Repository,
+ Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{Force: true})