Skip to content

Commit

Permalink
delete deleted file from index (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 8, 2023
1 parent 860a06b commit e9b0139
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ var addCmd = &cobra.Command{
}
for _, arg := range args {
if _, err := os.Stat(arg); os.IsNotExist(err) {
return fmt.Errorf(`path "%s" did not match any files`, arg)
// If the file does not exist but is registered in the index, delete it from the index
cleanedArg := filepath.Clean(arg)
cleanedArg = strings.ReplaceAll(cleanedArg, `\`, "/")
_, entry, isEntryFound := client.Idx.GetEntry([]byte(cleanedArg))
if !isEntryFound {
return fmt.Errorf(`path "%s" did not match any files`, arg)
}
if err := client.Idx.DeleteEntry(client.RootGoitPath, entry); err != nil {
return fmt.Errorf("fail to delete '%s' from index: %w", cleanedArg, err)
}
}
}

Expand Down Expand Up @@ -102,11 +111,6 @@ var addCmd = &cobra.Command{
}
}

// delete untracked files from index
if err := client.Idx.DeleteUntrackedFiles(client.RootGoitPath); err != nil {
return fmt.Errorf("fail to delete untracked files from index: %w", err)
}

return nil
},
}
Expand Down

0 comments on commit e9b0139

Please sign in to comment.