Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Keep scoped mirror commits limited to literal file and directory selections, so bracketed filenames do not include matching neighboring files.

- Add `crawlctl preservation verify` to check all remote backup content without retaining a second local copy.

- Add `crawlctl preservation inspect` to verify a pinned remote backup manifest without downloading chunks or writing files.
Expand Down
4 changes: 4 additions & 0 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ sidecars. Nonpositive limits leave file size unbounded.
- `backup` writes age-encrypted JSONL/Gzip shards and manifests, manages recipients and identities, lists Git-backed history, and verifies historical restores.
- `mirror` clones, initializes, pulls, commits, and pushes Git-backed archives. It also provides non-mutating fetches, immutable snapshot tags, Git-object reads, and history inspection.

`mirror.CommitPaths` selects files and directories literally after its existing
whitespace trimming and repository-relative validation. Git glob patterns and
pathspec magic are not expanded. Use `.` to commit the whole archive.

Managed sidecar trees reject overlapping source and destination roots, including
mixed relative and absolute paths. Configured root symlinks remain supported;
symlink directories inside a destination copy path are rejected so copying and
Expand Down
7 changes: 5 additions & 2 deletions mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ func Commit(ctx context.Context, opts Options, message string) (bool, error) {
return CommitPaths(ctx, opts, message, []string{"."})
}

// CommitPaths commits selected files or directories without Git pathspec expansion.
// Paths retain the existing whitespace trimming and repository-relative checks.
func CommitPaths(ctx context.Context, opts Options, message string, paths []string) (bool, error) {
opts = normalize(opts)
if message == "" {
Expand All @@ -306,7 +308,7 @@ func CommitPaths(ctx context.Context, opts Options, message string, paths []stri
if len(pathspecs) == 0 {
return false, nil
}
args := append([]string{"add", "--"}, pathspecs...)
args := append([]string{"--literal-pathspecs", "add", "--"}, pathspecs...)
if err := run(ctx, opts.RepoPath, opts.Git, args...); err != nil {
return false, err
}
Expand All @@ -318,6 +320,7 @@ func CommitPaths(ctx context.Context, opts Options, message string, paths []stri
return false, nil
}
commitArgs := []string{
"--literal-pathspecs",
"-c", "commit.gpgsign=false",
"-c", "user.name=crawlkit",
"-c", "user.email=crawlkit@example.invalid",
Expand Down Expand Up @@ -443,7 +446,7 @@ func cleanPathspecs(paths []string) ([]string, error) {

func staged(ctx context.Context, opts Options, pathspecs []string) (bool, error) {
opts = normalize(opts)
args := []string{"diff", "--cached", "--quiet", "--"}
args := []string{"--literal-pathspecs", "diff", "--cached", "--quiet", "--"}
args = append(args, pathspecs...)
out, err := output(ctx, opts.RepoPath, opts.Git, args...)
if err == nil {
Expand Down
67 changes: 67 additions & 0 deletions mirror/mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,73 @@ func TestCommitPathsDoesNotCommitPrestagedUnrelatedFiles(t *testing.T) {
}
}

func TestCommitPathsTreatsPathsLiterally(t *testing.T) {
for _, tc := range []struct {
name string
selected string
neighbor string
}{
{name: "file", selected: "notes[1].md", neighbor: "notes1.md"},
{name: "directory", selected: "archives[1]", neighbor: "archives1/note.md"},
} {
for _, prestaged := range []bool{false, true} {
name := tc.name + "/untracked"
if prestaged {
name = tc.name + "/prestaged"
}
t.Run(name, func(t *testing.T) {
ctx := context.Background()
opts := Options{RepoPath: t.TempDir()}
if err := EnsureRepo(ctx, opts); err != nil {
t.Fatal(err)
}
selectedFile := tc.selected
if tc.name == "directory" {
selectedFile += "/note.md"
}
for _, file := range []string{selectedFile, tc.neighbor} {
path := filepath.Join(opts.RepoPath, filepath.FromSlash(file))
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, []byte(file), 0o600); err != nil {
t.Fatal(err)
}
}
if prestaged {
if err := run(ctx, opts.RepoPath, "git", "add", "--", tc.neighbor); err != nil {
t.Fatal(err)
}
}
if committed, err := CommitPaths(ctx, opts, "archive: selected path", []string{tc.selected}); err != nil || !committed {
t.Fatalf("commit = %v, %v", committed, err)
}
tree, err := output(ctx, opts.RepoPath, "git", "ls-tree", "-r", "--name-only", "HEAD")
if err != nil {
t.Fatal(err)
}
if tree != selectedFile+"\n" {
t.Errorf("committed tree = %q, want only %q", tree, selectedFile)
}
staged, err := output(ctx, opts.RepoPath, "git", "diff", "--cached", "--name-only")
if err != nil {
t.Fatal(err)
}
wantStaged := ""
if prestaged {
wantStaged = tc.neighbor + "\n"
}
if staged != wantStaged {
t.Errorf("remaining staged files = %q, want %q", staged, wantStaged)
}
if committed, err := CommitPaths(ctx, opts, "archive: unchanged selection", []string{tc.selected}); err != nil || committed {
t.Errorf("unchanged selected path commit = %v, %v; want false, nil", committed, err)
}
})
}
}
}

func TestPullCurrentUsesExistingOrigin(t *testing.T) {
ctx := context.Background()
dir := t.TempDir()
Expand Down
Loading