Skip to content

Commit c24e1f1

Browse files
authored
Merge pull request #624 from numtide/feat/tmp-path
Introduce tmp path to better handle stdin
2 parents fd98385 + b68d328 commit c24e1f1

File tree

12 files changed

+183
-134
lines changed

12 files changed

+183
-134
lines changed

cmd/root_test.go

Lines changed: 139 additions & 113 deletions
Large diffs are not rendered by default.

format/formatter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ func (f *Formatter) Apply(ctx context.Context, files []*walk.File) error {
9090

9191
// append paths to the args
9292
for _, file := range files {
93-
args = append(args, file.RelPath)
93+
if file.TmpPath != "" {
94+
args = append(args, file.TmpPath)
95+
} else {
96+
args = append(args, file.RelPath)
97+
}
9498
}
9599

96100
// execute the command

nix/devshells/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pkgs.mkShellNoCC {
1515
graphviz
1616
cobra-cli
1717
enumer
18+
jujutsu
1819
])
1920
++ # include formatters for development and testing
2021
(import ../packages/treefmt/formatters.nix pkgs);

nix/packages/treefmt/formatters.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ with pkgs; [
1717
shfmt
1818
statix
1919
deadnix
20+
just
2021
opentofu
2122
dos2unix
2223
yamlfmt

test/examples/just/justfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# print this message
2+
help:
3+
just --list --list-submodules --unsorted
4+
5+
# interactive recipes launcher
6+
choose:
7+
just --choose --unsorted

test/examples/treefmt.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ includes = ["*.yaml"]
8989

9090
[formatter.foo-fmt]
9191
command = "foo-fmt"
92+
93+
[formatter.just]
94+
command = "just"
95+
options = ["--fmt", "--unstable", "--justfile"]
96+
includes = ["**/justfile"]

walk/cached.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (c *CachedReader) Read(ctx context.Context, files []*File) (n int, err erro
106106

107107
// set a release function which inserts this file into the update channel
108108
file.AddReleaseFunc(func(ctx context.Context) error {
109-
if !GetNoCache(ctx) {
109+
if !GetNoCache(ctx) && file.TmpPath == "" {
110110
c.updateCh <- file
111111
}
112112

walk/filesystem_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var examplesPaths = []string{
3333
"html/index.html",
3434
"html/scripts/.gitkeep",
3535
"javascript/source/hello.js",
36+
"just/justfile",
3637
"nix/sources.nix",
3738
"nixpkgs.toml",
3839
"python/main.py",
@@ -78,8 +79,8 @@ func TestFilesystemReader(t *testing.T) {
7879
}
7980
}
8081

81-
as.Equal(32, count)
82-
as.Equal(32, statz.Value(stats.Traversed))
82+
as.Equal(33, count)
83+
as.Equal(33, statz.Value(stats.Traversed))
8384
as.Equal(0, statz.Value(stats.Matched))
8485
as.Equal(0, statz.Value(stats.Formatted))
8586
as.Equal(0, statz.Value(stats.Changed))

walk/git_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func TestGitReader(t *testing.T) {
2929
reader, err := walk.NewGitReader(tempDir, "", &statz)
3030
as.NoError(err)
3131

32-
files := make([]*walk.File, 33)
32+
files := make([]*walk.File, 34)
3333
ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond)
3434
n, err := reader.Read(ctx, files)
3535

3636
cancel()
37-
as.Equal(32, n)
37+
as.Equal(33, n)
3838
as.ErrorIs(err, io.EOF)
3939

4040
// add everything to the git index
@@ -63,8 +63,8 @@ func TestGitReader(t *testing.T) {
6363
}
6464
}
6565

66-
as.Equal(32, count)
67-
as.Equal(32, statz.Value(stats.Traversed))
66+
as.Equal(33, count)
67+
as.Equal(33, statz.Value(stats.Traversed))
6868
as.Equal(0, statz.Value(stats.Matched))
6969
as.Equal(0, statz.Value(stats.Formatted))
7070
as.Equal(0, statz.Value(stats.Changed))

walk/jujutsu_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func TestJujutsuReader(t *testing.T) {
6767
}
6868
}
6969

70-
as.Equal(32, count)
71-
as.Equal(32, statz.Value(stats.Traversed))
70+
as.Equal(33, count)
71+
as.Equal(33, statz.Value(stats.Traversed))
7272
as.Equal(0, statz.Value(stats.Matched))
7373
as.Equal(0, statz.Value(stats.Formatted))
7474
as.Equal(0, statz.Value(stats.Changed))

0 commit comments

Comments
 (0)