Artifact 041ca3207b3eb4eb9a0a0a83b321335abab315a83b9aca12d20ee07eb1a58519:
- File
internal/checkout/manage_dir_test.go
— part of check-in
[9e28f473cc]
at
2026-10-21 16:48:01
on branch feat/submanifest-reader
— fix(checkout): adding a directory adds the files beneath it
Manage stored a named directory, "." included, as a tracked file, and the next commit failed reading it. A named directory now expands through the checkout's bounded, cone-aware walk to the files beneath it, skipping paths with a dot component as fossil's add does without --dotfiles; a file named explicitly is kept as given. An uncovered path is refused as such before its absence on disk is reported. (user: [email protected], size: 1954) [annotate] [blame] [check-ins using] [more...]
package checkout import ( "os" "path/filepath" "slices" "testing" ) // Naming a directory adds the files beneath it, as fossil's add does, and // never the directory itself: "." used to be stored as a file, and the next // commit failed reading it. Dotfiles found by the walk are skipped, as // fossil skips them without --dotfiles; one named explicitly is added. func TestManageExpandsDirectories(t *testing.T) { r, cleanup := newTestRepoWithCheckin(t) defer cleanup() dir := t.TempDir() co, err := Create(r, dir, CreateOpts{}) if err != nil { t.Fatal(err) } defer co.Close() rid, _, err := co.Version() if err != nil { t.Fatal(err) } if err := co.Extract(rid, ExtractOpts{}); err != nil { t.Fatal(err) } for name, data := range map[string]string{ "lib/a.go": "a", "lib/deep/b.go": "b", "lib/.hidden": "h", ".config/c": "c", "top.txt": "t", ".keep": "k", } { full := filepath.Join(dir, filepath.FromSlash(name)) if err := os.MkdirAll(filepath.Dir(full), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(full, []byte(data), 0o644); err != nil { t.Fatal(err) } } if _, err := co.Manage(ManageOpts{Paths: []string{"lib"}}); err != nil { t.Fatal(err) } if _, err := co.Manage(ManageOpts{Paths: []string{".", ".keep"}}); err != nil { t.Fatal(err) } rows, err := co.db.Query("SELECT pathname FROM vfile WHERE rid=0 ORDER BY pathname") if err != nil { t.Fatal(err) } defer rows.Close() var added []string for rows.Next() { var name string if err := rows.Scan(&name); err != nil { t.Fatal(err) } added = append(added, name) } if err := rows.Err(); err != nil { t.Fatal(err) } want := []string{".keep", "lib/a.go", "lib/deep/b.go", "top.txt"} if !slices.Equal(added, want) { t.Fatalf("added %q, want %q", added, want) } if _, _, err := co.Commit(CommitOpts{Message: "add tree", User: "test"}); err != nil { t.Fatalf("commit after adding a directory: %v", err) } }