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: worktree, add check to see if file already checked in. Fixes #718 #719

Merged
merged 1 commit into from May 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion worktree_status.go
Expand Up @@ -169,7 +169,9 @@ func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.
if len(path) != 0 {
isDir := (len(ch.To) > 0 && ch.To.IsDir()) || (len(ch.From) > 0 && ch.From.IsDir())
if m.Match(path, isDir) {
continue
if len(ch.From) == 0 {
continue
}
}
}
res = append(res, ch)
Expand Down
45 changes: 45 additions & 0 deletions worktree_test.go
Expand Up @@ -871,6 +871,51 @@ func (s *WorktreeSuite) TestStatusEmpty(c *C) {
c.Assert(status, NotNil)
}

func (s *WorktreeSuite) TestStatusCheckedInBeforeIgnored(c *C) {
fs := memfs.New()
storage := memory.NewStorage()

r, err := Init(storage, fs)
c.Assert(err, IsNil)

w, err := r.Worktree()
c.Assert(err, IsNil)

err = util.WriteFile(fs, "fileToIgnore", []byte("Initial data"), 0755)
c.Assert(err, IsNil)
_, err = w.Add("fileToIgnore")
c.Assert(err, IsNil)
_, err = w.Commit("Added file that will be ignored later", &CommitOptions{})
c.Assert(err, IsNil)

err = util.WriteFile(fs, ".gitignore", []byte("fileToIgnore\nsecondIgnoredFile"), 0755)
c.Assert(err, IsNil)
_, err = w.Add(".gitignore")
c.Assert(err, IsNil)
_, err = w.Commit("Added .gitignore", &CommitOptions{})
c.Assert(err, IsNil)
status, err := w.Status()
c.Assert(err, IsNil)
c.Assert(status.IsClean(), Equals, true)
c.Assert(status, NotNil)

err = util.WriteFile(fs, "secondIgnoredFile", []byte("Should be completly ignored"), 0755)
c.Assert(err, IsNil)
status = nil
status, err = w.Status()
c.Assert(err, IsNil)
c.Assert(status.IsClean(), Equals, true)
c.Assert(status, NotNil)

err = util.WriteFile(fs, "fileToIgnore", []byte("Updated data"), 0755)
c.Assert(err, IsNil)
status = nil
status, err = w.Status()
c.Assert(err, IsNil)
c.Assert(status.IsClean(), Equals, false)
c.Assert(status, NotNil)
}

func (s *WorktreeSuite) TestStatusEmptyDirty(c *C) {
fs := memfs.New()
err := util.WriteFile(fs, "foo", []byte("foo"), 0755)
Expand Down