From 2e092f909f643ef455d84dfa59282f0f0adf3c7a Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Wed, 3 May 2017 23:37:21 +0200 Subject: worktree: Status return empty status instead of nil --- worktree_status.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'worktree_status.go') diff --git a/worktree_status.go b/worktree_status.go index 46922da..f78a0c2 100644 --- a/worktree_status.go +++ b/worktree_status.go @@ -4,6 +4,8 @@ import ( "bytes" "io" + "fmt" + "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/filemode" "gopkg.in/src-d/go-git.v4/plumbing/format/index" @@ -19,7 +21,7 @@ import ( func (w *Worktree) Status() (Status, error) { ref, err := w.r.Head() if err == plumbing.ErrReferenceNotFound { - return nil, nil + return make(Status, 0), nil } if err != nil { @@ -177,7 +179,9 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) { return h, err } - if s.File(path).Worktree == Unmodified { + fmt.Println(len(s)) + fs := s.File(path) + if fs != nil && fs.Worktree == Unmodified { return h, nil } -- cgit From 5592dabdf9eed67c92b0e411ad375ae763119fd2 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Thu, 4 May 2017 00:09:55 +0200 Subject: worktree: Status return untracked for untracked files --- worktree_status.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'worktree_status.go') diff --git a/worktree_status.go b/worktree_status.go index f78a0c2..8dc743d 100644 --- a/worktree_status.go +++ b/worktree_status.go @@ -4,8 +4,6 @@ import ( "bytes" "io" - "fmt" - "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/filemode" "gopkg.in/src-d/go-git.v4/plumbing/format/index" @@ -48,10 +46,13 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) { switch a { case merkletrie.Delete: s.File(ch.From.String()).Staging = Deleted + s.File(ch.From.String()).Worktree = Unmodified case merkletrie.Insert: s.File(ch.To.String()).Staging = Added + s.File(ch.To.String()).Worktree = Unmodified case merkletrie.Modify: s.File(ch.To.String()).Staging = Modified + s.File(ch.To.String()).Worktree = Unmodified } } @@ -71,7 +72,6 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) { s.File(ch.From.String()).Worktree = Deleted case merkletrie.Insert: s.File(ch.To.String()).Worktree = Untracked - s.File(ch.To.String()).Staging = Untracked case merkletrie.Modify: s.File(ch.To.String()).Worktree = Modified } @@ -179,9 +179,7 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) { return h, err } - fmt.Println(len(s)) - fs := s.File(path) - if fs != nil && fs.Worktree == Unmodified { + if s.File(path).Worktree == Unmodified { return h, nil } -- cgit From 40fa5882a2c73f8c075403b7ec85870f04deda07 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Thu, 4 May 2017 01:45:28 +0200 Subject: worktree: Commit method implementation --- worktree_status.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'worktree_status.go') diff --git a/worktree_status.go b/worktree_status.go index 8dc743d..46953c7 100644 --- a/worktree_status.go +++ b/worktree_status.go @@ -43,16 +43,16 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) { return nil, err } + fs := s.File(nameFromAction(&ch)) + fs.Worktree = Unmodified + switch a { case merkletrie.Delete: s.File(ch.From.String()).Staging = Deleted - s.File(ch.From.String()).Worktree = Unmodified case merkletrie.Insert: s.File(ch.To.String()).Staging = Added - s.File(ch.To.String()).Worktree = Unmodified case merkletrie.Modify: s.File(ch.To.String()).Staging = Modified - s.File(ch.To.String()).Worktree = Unmodified } } @@ -67,19 +67,34 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) { return nil, err } + fs := s.File(nameFromAction(&ch)) + if fs.Staging == Untracked { + fs.Staging = Unmodified + } + switch a { case merkletrie.Delete: - s.File(ch.From.String()).Worktree = Deleted + fs.Worktree = Deleted case merkletrie.Insert: - s.File(ch.To.String()).Worktree = Untracked + fs.Worktree = Untracked + fs.Staging = Untracked case merkletrie.Modify: - s.File(ch.To.String()).Worktree = Modified + fs.Worktree = Modified } } return s, nil } +func nameFromAction(ch *merkletrie.Change) string { + name := ch.To.String() + if name == "" { + return ch.From.String() + } + + return name +} + func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) { idx, err := w.r.Storer.Index() if err != nil { -- cgit