Skip to content

Commit

Permalink
delete deleteUntrackedFiles function (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 8, 2023
1 parent 374b509 commit f11f1ba
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 28 deletions.
5 changes: 0 additions & 5 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ var commitCmd = &cobra.Command{
return err
}
} else {
// check if files are deleted
if err := client.Idx.DeleteUntrackedFiles(client.RootGoitPath); err != nil {
return fmt.Errorf("fail to delete untracked files: %w", err)
}

// compare last commit with index
isCommitNecessary, err := isCommitNecessary(client.Head.Commit)
if err != nil {
Expand Down
23 changes: 0 additions & 23 deletions internal/store/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,6 @@ func (idx *Index) DeleteEntry(rootGoitPath string, entry *Entry) error {
return nil
}

func (idx *Index) DeleteUntrackedFiles(rootGoitPath string) error {
var trackedEntries []*Entry
for _, entry := range idx.Entries {
if _, err := os.Stat(string(entry.Path)); !os.IsNotExist(err) {
trackedEntries = append(trackedEntries, entry)
}
}

// no need to delete
if len(trackedEntries) == int(idx.EntryNum) {
return nil
}

// need to update index
idx.Entries = trackedEntries
idx.EntryNum = uint32(len(idx.Entries))
if err := idx.write(rootGoitPath); err != nil {
return err
}

return nil
}

func (idx *Index) read(rootGoitPath string) error {
// read index
indexPath := filepath.Join(rootGoitPath, "index")
Expand Down

0 comments on commit f11f1ba

Please sign in to comment.