bonchi 0.2.0.rc1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bonchi/cli.rb +67 -0
- data/lib/bonchi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f726dfa32881aaae2a225b30e26b3a31fe3bfa2714709a33738910c4a42d2daf
|
|
4
|
+
data.tar.gz: 4ef9df6de06aecfc41d5bf69fe651114123bccb48b0fb9cc67ed8c26f1ab6bcb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5388c61deec0daf249af8c2033772bf9c2b22d51a894b6cfb75f887d65d14c1bdf298d7e96d6c7513717b0d0676fcb0f5f5a7bf518227be3b380487afd8774f3
|
|
7
|
+
data.tar.gz: 919fe02691d9f5b4c7ca3c2ac31c8cb365b6bb9533ac56470d2803d972881f3375ee3b72a64ecbb4e983e29898629d331f451808ee20b56e418df7d4ab91a671
|
data/lib/bonchi/cli.rb
CHANGED
|
@@ -14,6 +14,13 @@ module Bonchi
|
|
|
14
14
|
map "-v" => :version
|
|
15
15
|
|
|
16
16
|
desc "create BRANCH [BASE]", "Create new branch + worktree"
|
|
17
|
+
long_desc <<~DESC
|
|
18
|
+
Create a new branch and worktree. BASE defaults to the repository's default branch
|
|
19
|
+
(e.g. main). If a worktree for BRANCH already exists, switches to it instead.
|
|
20
|
+
|
|
21
|
+
When a .worktree.yml exists in the main worktree, setup runs automatically
|
|
22
|
+
(copy files, allocate ports, run pre_setup and setup commands). Skip with --no-setup.
|
|
23
|
+
DESC
|
|
17
24
|
option :setup, type: :boolean, default: true, desc: "Run setup after creating worktree"
|
|
18
25
|
def create(branch, base = nil)
|
|
19
26
|
base ||= Git.default_base_branch
|
|
@@ -38,6 +45,13 @@ module Bonchi
|
|
|
38
45
|
end
|
|
39
46
|
|
|
40
47
|
desc "switch BRANCH", "Switch to existing branch in worktree"
|
|
48
|
+
long_desc <<~DESC
|
|
49
|
+
Create a worktree for an existing branch and cd into it.
|
|
50
|
+
If a worktree for BRANCH already exists, switches to it instead.
|
|
51
|
+
|
|
52
|
+
The branch must already exist locally or on the remote.
|
|
53
|
+
To create a new branch, use `bonchi create` instead.
|
|
54
|
+
DESC
|
|
41
55
|
def switch(branch)
|
|
42
56
|
existing = Git.worktree_path_for(branch)
|
|
43
57
|
if existing
|
|
@@ -58,6 +72,13 @@ module Bonchi
|
|
|
58
72
|
end
|
|
59
73
|
|
|
60
74
|
desc "pr NUMBER_OR_URL", "Checkout GitHub PR in worktree"
|
|
75
|
+
long_desc <<~DESC
|
|
76
|
+
Fetch a GitHub pull request and check it out in a new worktree.
|
|
77
|
+
Accepts a PR number (e.g. 123) or a full GitHub PR URL.
|
|
78
|
+
|
|
79
|
+
The worktree branch will be named pr-<number>.
|
|
80
|
+
If the worktree already exists, switches to it instead.
|
|
81
|
+
DESC
|
|
61
82
|
def pr(input)
|
|
62
83
|
pr_number = extract_pr_number(input)
|
|
63
84
|
branch = "pr-#{pr_number}"
|
|
@@ -77,6 +98,22 @@ module Bonchi
|
|
|
77
98
|
signal_cd(path)
|
|
78
99
|
end
|
|
79
100
|
|
|
101
|
+
desc "init", "Generate a .worktree.yml in the current project"
|
|
102
|
+
long_desc <<~DESC
|
|
103
|
+
Generate a .worktree.yml config file in the current directory with
|
|
104
|
+
sensible defaults. Edit the file to customize which files to copy,
|
|
105
|
+
which ports to allocate, and what setup command to run.
|
|
106
|
+
DESC
|
|
107
|
+
def init
|
|
108
|
+
path = File.join(Dir.pwd, ".worktree.yml")
|
|
109
|
+
if File.exist?(path)
|
|
110
|
+
abort "Error: .worktree.yml already exists"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
File.write(path, WORKTREE_YML_TEMPLATE)
|
|
114
|
+
puts "Created #{path}"
|
|
115
|
+
end
|
|
116
|
+
|
|
80
117
|
desc "setup [-- ARGS...]", "Run setup in current worktree (ports, copy, pre_setup, setup cmd)"
|
|
81
118
|
def setup(*args)
|
|
82
119
|
Setup.new.run(args)
|
|
@@ -88,6 +125,12 @@ module Bonchi
|
|
|
88
125
|
end
|
|
89
126
|
|
|
90
127
|
desc "remove BRANCH", "Remove a worktree"
|
|
128
|
+
long_desc <<~DESC
|
|
129
|
+
Remove a worktree and its directory. Refuses to remove worktrees
|
|
130
|
+
with uncommitted changes or untracked files (use `git worktree remove --force` to override).
|
|
131
|
+
|
|
132
|
+
Aliases: rm
|
|
133
|
+
DESC
|
|
91
134
|
def remove(branch)
|
|
92
135
|
path = Git.worktree_path_for(branch)
|
|
93
136
|
abort "Error: No worktree found for branch: #{branch}" unless path
|
|
@@ -97,6 +140,13 @@ module Bonchi
|
|
|
97
140
|
end
|
|
98
141
|
|
|
99
142
|
desc "prune", "Prune stale worktree admin files"
|
|
143
|
+
long_desc <<~DESC
|
|
144
|
+
Clean up stale worktree tracking data. Git internally tracks worktrees in
|
|
145
|
+
.git/worktrees/. When a worktree directory is deleted manually (e.g. rm -rf)
|
|
146
|
+
instead of via `bonchi remove`, the tracking data becomes stale.
|
|
147
|
+
|
|
148
|
+
This runs `git worktree prune` to remove those orphaned entries.
|
|
149
|
+
DESC
|
|
100
150
|
def prune
|
|
101
151
|
Git.worktree_prune
|
|
102
152
|
puts "Pruned stale worktree administrative files"
|
|
@@ -133,6 +183,23 @@ module Bonchi
|
|
|
133
183
|
end
|
|
134
184
|
end
|
|
135
185
|
|
|
186
|
+
WORKTREE_YML_TEMPLATE = <<~'YAML'
|
|
187
|
+
# Files to copy from the main worktree before setup.
|
|
188
|
+
# copy:
|
|
189
|
+
# - .env.local
|
|
190
|
+
|
|
191
|
+
# Env var names to allocate unique ports for (from global pool).
|
|
192
|
+
# ports:
|
|
193
|
+
# - PORT
|
|
194
|
+
|
|
195
|
+
# Commands to run before the setup command (port env vars are available).
|
|
196
|
+
# pre_setup:
|
|
197
|
+
# - sed -i '' "s|^PORT=.*|PORT=$PORT|" .env.local
|
|
198
|
+
|
|
199
|
+
# The setup command to run (default: bin/setup).
|
|
200
|
+
setup: bin/setup
|
|
201
|
+
YAML
|
|
202
|
+
|
|
136
203
|
SHELL_ENV = <<~'SHELL'
|
|
137
204
|
bonchi() {
|
|
138
205
|
local bonchi_cd_file="${TMPDIR:-/tmp}/bonchi_cd.$$"
|
data/lib/bonchi/version.rb
CHANGED