A vibe coded tangled fork which supports pijul.
1package pijul
2
3import (
4 "fmt"
5)
6
7// Diff represents the difference between two states
8type Diff struct {
9 Raw string `json:"raw"`
10 Files []FileDiff `json:"files,omitempty"`
11 Stats *DiffStats `json:"stats,omitempty"`
12}
13
14// FileDiff represents changes to a single file
15type FileDiff struct {
16 Path string `json:"path"`
17 OldPath string `json:"old_path,omitempty"` // for renames
18 Status string `json:"status"` // added, modified, deleted, renamed
19 Additions int `json:"additions"`
20 Deletions int `json:"deletions"`
21 Patch string `json:"patch,omitempty"`
22}
23
24// DiffStats contains summary statistics for a diff
25type DiffStats struct {
26 FilesChanged int `json:"files_changed"`
27 Additions int `json:"additions"`
28 Deletions int `json:"deletions"`
29}
30
31// Diff returns the diff of uncommitted changes
32func (p *PijulRepo) Diff() (*Diff, error) {
33 output, err := p.diff()
34 if err != nil {
35 return nil, fmt.Errorf("pijul diff: %w", err)
36 }
37
38 return &Diff{
39 Raw: string(output),
40 }, nil
41}
42
43// DiffChange returns the diff for a specific change
44func (p *PijulRepo) DiffChange(hash string) (*Diff, error) {
45 output, err := p.change(hash)
46 if err != nil {
47 return nil, fmt.Errorf("pijul change %s: %w", hash, err)
48 }
49
50 return &Diff{
51 Raw: string(output),
52 }, nil
53}
54
55// DiffBetween returns the diff between two channels or states
56func (p *PijulRepo) DiffBetween(from, to string) (*Diff, error) {
57 args := []string{}
58 if from != "" {
59 args = append(args, "--channel", from)
60 }
61 if to != "" {
62 args = append(args, "--channel", to)
63 }
64
65 output, err := p.diff(args...)
66 if err != nil {
67 return nil, fmt.Errorf("pijul diff: %w", err)
68 }
69
70 return &Diff{
71 Raw: string(output),
72 }, nil
73}