A vibe coded tangled fork which supports pijul.
1package pijul
2
3import (
4 "bytes"
5 "fmt"
6 "os"
7 "os/exec"
8)
9
10// InitBare initializes a bare Pijul repository
11func InitBare(repoPath string) error {
12 if err := os.MkdirAll(repoPath, 0755); err != nil {
13 return fmt.Errorf("creating directory: %w", err)
14 }
15
16 cmd := exec.Command("pijul", "init")
17 cmd.Dir = repoPath
18
19 var stderr bytes.Buffer
20 cmd.Stderr = &stderr
21
22 if err := cmd.Run(); err != nil {
23 return fmt.Errorf("pijul init: %w, stderr: %s", err, stderr.String())
24 }
25
26 // remove .ignore auto-generated by pijul init
27 os.Remove(fmt.Sprintf("%s/.ignore", repoPath))
28
29 return nil
30}
31
32// Fork clones a repository to a new location
33func Fork(srcPath, destPath string) error {
34 // For local fork, we can use pijul clone
35 cmd := exec.Command("pijul", "clone", srcPath, destPath)
36
37 var stderr bytes.Buffer
38 cmd.Stderr = &stderr
39
40 if err := cmd.Run(); err != nil {
41 return fmt.Errorf("pijul clone: %w, stderr: %s", err, stderr.String())
42 }
43
44 return nil
45}
46
47// Push pushes changes to a remote
48func (p *PijulRepo) Push(remote string, channel string) error {
49 args := []string{remote}
50 if channel != "" {
51 args = append(args, "--channel", channel)
52 }
53
54 _, err := p.runPijulCmd("push", args...)
55 return err
56}
57
58// Pull pulls changes from a remote
59func (p *PijulRepo) Pull(remote string, channel string) error {
60 args := []string{remote}
61 if channel != "" {
62 args = append(args, "--channel", channel)
63 }
64
65 _, err := p.runPijulCmd("pull", args...)
66 return err
67}
68
69// Apply applies a change to the repository
70func (p *PijulRepo) Apply(changeHash string) error {
71 _, err := p.runPijulCmd("apply", changeHash)
72 return err
73}
74
75// Unrecord removes a change from the channel (like git reset)
76func (p *PijulRepo) Unrecord(changeHash string) error {
77 args := []string{changeHash}
78 if p.channelName != "" {
79 args = append(args, "--channel", p.channelName)
80 }
81 _, err := p.runPijulCmd("unrecord", args...)
82 return err
83}
84
85// Record creates a new change (like git commit)
86func (p *PijulRepo) Record(message string, authors []Author) error {
87 args := []string{"-m", message}
88
89 for _, author := range authors {
90 authorStr := author.Name
91 if author.Email != "" {
92 authorStr = fmt.Sprintf("%s <%s>", author.Name, author.Email)
93 }
94 args = append(args, "--author", authorStr)
95 }
96
97 if p.channelName != "" {
98 args = append(args, "--channel", p.channelName)
99 }
100
101 _, err := p.runPijulCmd("record", args...)
102 return err
103}
104
105// Add adds files to be tracked
106func (p *PijulRepo) Add(paths ...string) error {
107 args := append([]string{}, paths...)
108 _, err := p.runPijulCmd("add", args...)
109 return err
110}
111
112// Remove removes files from tracking
113func (p *PijulRepo) Remove(paths ...string) error {
114 args := append([]string{}, paths...)
115 _, err := p.runPijulCmd("remove", args...)
116 return err
117}