aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-26 21:46:49 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-26 21:46:49 +0200
commitab590eb89849a0319b8c5a4d7fd980137da7180d (patch)
tree15544e667d27d87ebd9b73295e11351d85e1a008 /worktree.go
parente19163e22eb19b352dd022f6edc9d81e1cd7a7ed (diff)
downloadgo-git-ab590eb89849a0319b8c5a4d7fd980137da7180d.tar.gz
worktree: expose underlying filesystem
Diffstat (limited to 'worktree.go')
-rw-r--r--worktree.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/worktree.go b/worktree.go
index 5768888..b821695 100644
--- a/worktree.go
+++ b/worktree.go
@@ -29,8 +29,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.
@@ -355,13 +357,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
}
@@ -385,7 +387,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
}
@@ -402,7 +404,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
}
@@ -429,7 +431,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
}
@@ -453,7 +455,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
}
@@ -468,7 +470,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
}
@@ -577,7 +579,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