Skip to content

Commit

Permalink
fix bug (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 24, 2023
1 parent 381c116 commit 3e4cefb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var addCmd = &cobra.Command{
// check if the arg is the target of excluding path
cleanedArg := filepath.Clean(arg)
cleanedArg = strings.ReplaceAll(cleanedArg, `\`, "/")
if client.Ignore.IsIncluded(cleanedArg) {
if client.Ignore.IsIncluded(cleanedArg, client.Idx) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var statusCmd = &cobra.Command{
// walk through working directory
var newFiles []string
var modifiedFiles []string
filePaths, err := file.GetFilePathsUnderDirectoryWithIgnore(".", client.Ignore)
filePaths, err := file.GetFilePathsUnderDirectoryWithIgnore(".", client.Idx, client.Ignore)
if err != nil {
return fmt.Errorf("fail to get files: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/file/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetFilePathsUnderDirectory(path string) ([]string, error) {
return filePaths, nil
}

func GetFilePathsUnderDirectoryWithIgnore(path string, ignore *store.Ignore) ([]string, error) {
func GetFilePathsUnderDirectoryWithIgnore(path string, index *store.Index, ignore *store.Ignore) ([]string, error) {
files, err := os.ReadDir(path)
if err != nil {
return nil, err
Expand All @@ -66,12 +66,12 @@ func GetFilePathsUnderDirectoryWithIgnore(path string, ignore *store.Ignore) ([]
} else {
filePath = fmt.Sprintf("%s/%s", path, file.Name())
}
if ignore.IsIncluded(filePath) {
if ignore.IsIncluded(filePath, index) {
continue
}

if file.IsDir() {
gotFilePaths, err := GetFilePathsUnderDirectoryWithIgnore(filePath, ignore)
gotFilePaths, err := GetFilePathsUnderDirectoryWithIgnore(filePath, index, ignore)
if err != nil {
return nil, err
}
Expand Down
14 changes: 10 additions & 4 deletions internal/store/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ func (i *Ignore) load(rootGoitPath string) error {
}

// return true if the parameter is included in ignore list
func (i *Ignore) IsIncluded(path string) bool {
func (i *Ignore) IsIncluded(path string, index *Index) bool {
target := path
info, _ := os.Stat(path)
if info.IsDir() && !directoryRegexp.MatchString(path) {
target = fmt.Sprintf("%s/", path)
info, err := os.Stat(path)
if os.IsNotExist(err) {
if len(index.GetEntriesByDirectory(path)) > 0 {
target = fmt.Sprintf("%s/", path)
}
} else {
if info.IsDir() && !directoryRegexp.MatchString(path) {
target = fmt.Sprintf("%s/", path)
}
}
for _, exFile := range i.paths {
exRegexp := regexp.MustCompile(exFile)
Expand Down
2 changes: 1 addition & 1 deletion internal/store/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (idx *Index) DiffWithTree(tree *object.Tree) ([]*DiffEntry, error) {
if !isRegistered {
diffEntries = append(diffEntries, &DiffEntry{
Dt: diffDelete,
Entry: entry,
Entry: gotEntry,
})
} else if !entry.Hash.Compare(gotEntry.Hash) {
diffEntries = append(diffEntries, &DiffEntry{
Expand Down

0 comments on commit 3e4cefb

Please sign in to comment.