Skip to content

Commit

Permalink
add remove file process (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 21, 2023
1 parent 73498d2 commit a28078b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -37,6 +38,24 @@ var rmCmd = &cobra.Command{
}
}

// remove file from working tree and index
for _, arg := range args {
cleanedArg := filepath.Clean(arg)
cleanedArg = strings.ReplaceAll(cleanedArg, `\`, "/")

// remove from the working tree
if _, err := os.Stat(cleanedArg); !os.IsNotExist(err) {
if err := os.Remove(cleanedArg); err != nil {
return fmt.Errorf("fail to delete %s from the working tree: %w", cleanedArg, err)
}
}

// remove from the index
if err := client.Idx.DeleteEntry(client.RootGoitPath, []byte(cleanedArg)); err != nil {
return fmt.Errorf("fail to delete '%s' from the index: %w", cleanedArg, err)
}
}

return nil
},
}
Expand Down

0 comments on commit a28078b

Please sign in to comment.