Skip to content

Commit

Permalink
fix subpath detection
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jan 30, 2020
1 parent 3b47d1e commit c676346
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,8 @@ func ll(cwd string) {
}
// gitStatus returns file names of modified files from repo root.
fullPath := filepath.Join(cwd, name)
if file.IsDir() {
fullPath += "/"
}
for path, mode := range status {
// Use HasPrefix instead of exact mach to highlight directories as well.
if HasPrefix(path, fullPath) {
if subPath(path, fullPath) {
if mode[0] == '?' || mode[1] == '?' {
modes[name] = untracked
} else if mode[0] == 'A' || mode[1] == 'A' {
Expand Down Expand Up @@ -159,6 +155,19 @@ start:
fmt.Println(Join(output, "\n"))
}

func subPath(path string, fullPath string) bool {
p := Split(path, "/")
for i, s := range Split(fullPath, "/") {
if i >= len(p) {
return false
}
if p[i] != s {
return false
}
}
return true
}

func gitRepo() (string, error) {
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
var out bytes.Buffer
Expand Down

0 comments on commit c676346

Please sign in to comment.