-
Notifications
You must be signed in to change notification settings - Fork 49
fix: ignore git submodules #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "os/exec" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/charmbracelet/log" | ||
| "github.com/numtide/treefmt/v2/git" | ||
|
|
@@ -38,7 +39,7 @@ func (g *GitReader) Read(ctx context.Context, files []*File) (n int, err error) | |
| r, w := io.Pipe() | ||
|
|
||
| // create a command which will execute from the specified sub path within root | ||
| cmd := exec.Command("git", "ls-files", "--cached", "--others", "--exclude-standard") | ||
| cmd := exec.Command("git", "ls-files", "--cached", "--others", "--exclude-standard", "--stage") | ||
| cmd.Dir = filepath.Join(g.root, g.path) | ||
| cmd.Stdout = w | ||
|
|
||
|
|
@@ -51,19 +52,39 @@ func (g *GitReader) Read(ctx context.Context, files []*File) (n int, err error) | |
| g.scanner = bufio.NewScanner(r) | ||
| } | ||
|
|
||
| nextLine := func() (string, error) { | ||
| line := g.scanner.Text() | ||
| nextFile := func() (string, error) { | ||
| for line := g.scanner.Text(); len(line) > 0; line = g.scanner.Text() { | ||
| lineSplit := strings.Split(line, "\t") | ||
|
|
||
| if len(line) == 0 || line[0] != '"' { | ||
| return line, nil | ||
| } | ||
| var stage, file string | ||
| // Untracked files just show as `<filename>`, while tracked files show as `<mode> <object> <stage><TAB><file>` | ||
| if len(lineSplit) == 1 { | ||
| stage, file = "", lineSplit[0] | ||
| } else { | ||
| stage, file = lineSplit[0], lineSplit[1] | ||
| } | ||
bitbloxhub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // 160000 is the mode for submodules, skip them because they are separate projects that may have their own | ||
| // formatting rules | ||
| if strings.HasPrefix(stage, "160000") { | ||
| g.scanner.Scan() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why we need this here. Won't the for loop do the right thing when we
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because this loop just calls
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhh, got it. Your call, whatever you prefer.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't get the refactor to work, so I guess we can just leave this here for now. |
||
|
|
||
| continue | ||
| } | ||
|
|
||
| if file[0] != '"' { | ||
| return file, nil | ||
| } | ||
|
|
||
| unquoted, err := strconv.Unquote(file) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to unquote file %s: %w", file, err) | ||
| } | ||
|
|
||
| unquoted, err := strconv.Unquote(line) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to unquote line %s: %w", line, err) | ||
| return unquoted, nil | ||
| } | ||
|
|
||
| return unquoted, nil | ||
| return "", io.EOF | ||
| } | ||
|
|
||
| LOOP: | ||
|
|
@@ -82,7 +103,7 @@ LOOP: | |
| default: | ||
| // read the next file | ||
| if g.scanner.Scan() { | ||
| entry, err := nextLine() | ||
| entry, err := nextFile() | ||
| if err != nil { | ||
| return n, err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.