diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-06-21 11:17:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-21 11:17:04 -0700 |
commit | ad02bf020460c210660db4fffda7f926b6aae95a (patch) | |
tree | 60423e7f3ab29530f1a61865abf55a6320200897 | |
parent | 4046ad933a32567c2267f05a972202b8c7cd92d0 (diff) | |
parent | 81dbc6a6e5cf5278ba3be981247fd702d5102cef (diff) | |
download | go-git-ad02bf020460c210660db4fffda7f926b6aae95a.tar.gz |
Merge pull request #444 from silvertern/gitignore-ch2v4.0.0-rc11
Fixes checkout not possible with (untracked) files under gitignore
-rw-r--r-- | worktree_status.go | 8 | ||||
-rw-r--r-- | worktree_test.go | 34 |
2 files changed, 35 insertions, 7 deletions
diff --git a/worktree_status.go b/worktree_status.go index 7116445..728d7a0 100644 --- a/worktree_status.go +++ b/worktree_status.go @@ -68,8 +68,6 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) { return nil, err } - right = w.excludeIgnoredChanges(right) - for _, ch := range right { a, err := ch.Action() if err != nil { @@ -117,7 +115,11 @@ func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) { } to := filesystem.NewRootNode(w.fs, submodules) - return merkletrie.DiffTree(from, to, diffTreeIsEquals) + res, err := merkletrie.DiffTree(from, to, diffTreeIsEquals) + if err == nil { + res = w.excludeIgnoredChanges(res) + } + return res, err } func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes { diff --git a/worktree_test.go b/worktree_test.go index 5d0d131..875f8d5 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -307,6 +307,35 @@ func (s *WorktreeSuite) testCheckoutBisect(c *C, url string) { }) } +func (s *WorktreeSuite) TestCheckoutWithGitignore(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + fs: fs, + } + + err := w.Checkout(&CheckoutOptions{}) + c.Assert(err, IsNil) + + f, _ := fs.Create("file") + f.Close() + + err = w.Checkout(&CheckoutOptions{}) + c.Assert(err.Error(), Equals, "worktree contains unstagged changes") + + f, _ = fs.Create(".gitignore") + f.Write([]byte("file")) + f.Close() + + err = w.Checkout(&CheckoutOptions{}) + c.Assert(err.Error(), Equals, "worktree contains unstagged changes") + + w.Add(".gitignore") + + err = w.Checkout(&CheckoutOptions{}) + c.Assert(err, IsNil) +} + func (s *WorktreeSuite) TestStatus(c *C) { fs := memfs.New() w := &Worktree{ @@ -458,10 +487,7 @@ func (s *WorktreeSuite) TestStatusModified(c *C) { } func (s *WorktreeSuite) TestStatusIgnored(c *C) { - dir, _ := ioutil.TempDir("", "status") - defer os.RemoveAll(dir) - - fs := osfs.New(filepath.Join(dir, "worktree")) + fs := memfs.New() w := &Worktree{ r: s.Repository, fs: fs, |