1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//! clap definitions and dispatch. Every command self-documents.
use crate::ops;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(
name = "rv",
version,
about = "repoverse — multi-repo workspace & rollup tool",
long_about = "Keep many independent git repos in sync and roll changes up \
across dependency boundaries. See `rv help <cmd>`."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Cmd,
}
#[derive(Subcommand, Debug)]
pub enum Cmd {
/// Symlink-safe git status for the workspace or one checkout
Status {
/// Emit machine-readable JSON
#[arg(long)]
json: bool,
/// Show only dirty repos and their changed files
#[arg(long)]
dirty: bool,
/// Project path/name to inspect with symlink-safe git status
target: Option<String>,
},
/// Show the workspace's shared checkout layout
Layout,
/// Check Repoverse workspace health and suggest or apply safe repairs
Doctor {
/// Apply safe local repairs such as missing skip-worktree flags
#[arg(long)]
fix: bool,
},
/// Check or stamp committed gitlinks from current Repoverse checkouts
Gitlinks {
/// Update mismatched gitlinks and commit each changed consumer
#[arg(long)]
commit: bool,
},
/// Clone/initialize the workspace from .repoverse.yaml
Init {
/// Force HTTPS remotes
#[arg(long, conflicts_with = "ssh")]
https: bool,
/// Force SSH remotes
#[arg(long)]
ssh: bool,
},
/// Fetch all remotes in parallel
Fetch {
/// Parallel jobs
#[arg(short = 'j', long, default_value_t = 8)]
jobs: usize,
targets: Vec<String>,
},
/// Work with configured upstream source remotes
Upstream {
#[command(subcommand)]
command: UpstreamCmd,
},
/// Pull repos on their branches, restoring overlays around git pull
Pull {
#[arg(long)]
rebase: bool,
targets: Vec<String>,
},
/// Run git merge in selected/current repos, restoring overlays around git merge
Merge {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Run git rebase in selected/current repos, restoring overlays around git rebase
Rebase {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Checkout the workspace to .repoverse.lock, restoring overlays around git checkout
Sync {
/// Discard local changes
#[arg(long)]
force: bool,
},
/// Write .repoverse.lock = current HEADs
Pin,
/// Move the lock forward to current tips of the yaml's branches
Update,
/// Create a branch in dirty repos (smart mode)
Branch { name: String },
/// Checkout a revision in selected/current repos, restoring overlays around git checkout
Checkout {
rev: String,
targets: Vec<String>,
#[arg(long)]
reset: bool,
},
/// Checkout/create a branch across selected repos, restoring overlays around git checkout
Switch {
#[arg(short = 'b')]
create: bool,
branch: String,
targets: Vec<String>,
},
/// Re-point existing clones to ssh|https
Remote {
#[arg(value_parser = ["ssh", "https"])]
scheme: String,
},
/// Atomic cross-repo commit with the same message
Commit {
#[arg(short = 'm')]
message: String,
targets: Vec<String>,
},
/// Re-establish shared-dep symlinks from config (run after a fresh clone)
Link,
/// Restore shared overlays to real submodules (before git history ops)
Unlink {
/// Remove overlays without hydrating submodule checkouts
#[arg(long)]
no_submodules: bool,
/// Only this repo (owner/repo or short name); default: all
repo: Option<String>,
},
/// Push repos on feature branches
Push,
/// Open PRs: sub-repos first, then root with cross-links (needs gh)
Pr {
/// Print the resolved PR plan without creating PRs
#[arg(long)]
dry_run: bool,
#[arg(long)]
json: bool,
},
/// Pin + commit the lock + tag a release
Release { tag: Option<String> },
/// Install project dependencies per repo
Setup { targets: Vec<String> },
/// Run lint in dirty repos (parallel, quiet on success)
Lint {
#[arg(long)]
force: bool,
targets: Vec<String>,
},
/// Run tests in dirty repos
Test {
#[arg(long)]
force: bool,
targets: Vec<String>,
},
/// Lint + test dirty repos by default
Check {
/// Explicitly check dirty repos only (default)
#[arg(long, conflicts_with = "all")]
dirty: bool,
/// Check all configured repos, even clean ones
#[arg(long)]
all: bool,
#[arg(long)]
json: bool,
targets: Vec<String>,
},
/// Migrate a Google-repo manifest.xml into .repoverse.yaml
Import { manifest: String },
/// Wizard: adopt an existing nested-submodule project
Adopt {
/// Recursively scan submodules and print a leaf-up conversion plan
#[arg(long)]
plan: bool,
/// Lift one repo to a single shared copy (dry-run unless --yes)
#[arg(long, value_name = "REPO")]
step: Option<String>,
/// Directory (workspace-relative) to place the shared copy in
/// [default: ./repos/<repo>]
#[arg(long, value_name = "DIR")]
into: Option<String>,
/// Rewrite each consumer's .gitmodules `branch=` to this branch
/// (stages it; kills phantom branch-conflicts). Not pushed.
#[arg(long, value_name = "BRANCH")]
normalize_branch: Option<String>,
/// Also write a per-repo .repoverse.yaml into each consumer
/// (only for repos built/cloned standalone; default off)
#[arg(long)]
standalone: bool,
#[arg(long)]
json: bool,
/// Actually perform the step (otherwise dry-run)
#[arg(long)]
yes: bool,
#[arg(long)]
dry_run: bool,
},
/// Show the full ordered dependency DAG with per-node status
Plan {
#[arg(long)]
json: bool,
},
/// The single next actionable node (agent loop primitive)
Next {
#[arg(long)]
json: bool,
},
/// Dependency-ordered rollup cascade
Rollup {
#[arg(long)]
dry_run: bool,
#[arg(long)]
direct: bool,
#[arg(long)]
step: bool,
#[arg(long)]
from: Option<String>,
#[arg(long)]
slug: Option<String>,
},
}
#[derive(Subcommand, Debug)]
pub enum UpstreamCmd {
/// Fetch configured upstream remotes without merging
Fetch {
/// Parallel jobs
#[arg(short = 'j', long, default_value_t = 8)]
jobs: usize,
targets: Vec<String>,
},
}
pub fn run(cli: Cli) -> Result<()> {
match cli.command {
Cmd::Status {
json,
dirty,
target,
} => ops::status::run(json, dirty, target.as_deref()),
Cmd::Layout => ops::status::layout(),
Cmd::Doctor { fix } => ops::doctor::run(fix),
Cmd::Gitlinks { commit } => ops::gitlinks::run(commit),
Cmd::Init { https, ssh } => ops::init::run(https, ssh),
Cmd::Fetch { jobs, targets } => ops::fetch::run(jobs, &targets),
Cmd::Upstream { command } => match command {
UpstreamCmd::Fetch { jobs, targets } => ops::upstream::fetch(jobs, &targets),
},
Cmd::Pull { rebase, targets } => ops::pull::run(rebase, &targets),
Cmd::Merge { args } => ops::history::run(ops::history::Action::Merge, &args),
Cmd::Rebase { args } => ops::history::run(ops::history::Action::Rebase, &args),
Cmd::Sync { force } => ops::sync::run(force),
Cmd::Pin => ops::pin::run(),
Cmd::Update => ops::update::run(),
Cmd::Branch { name } => ops::branch::run(&name),
Cmd::Checkout {
rev,
targets,
reset,
} => ops::checkout::run(&rev, &targets, reset),
Cmd::Switch {
create,
branch,
targets,
} => ops::switch::run(create, &branch, &targets),
Cmd::Remote { scheme } => ops::remote_cmd::run(&scheme),
Cmd::Commit { message, targets } => ops::commit::run(&message, &targets),
Cmd::Link => ops::adopt::relink(),
Cmd::Unlink {
no_submodules,
repo,
} => ops::adopt::unlink(repo.as_deref(), !no_submodules),
Cmd::Push => ops::push::run(),
Cmd::Pr { dry_run, json } => ops::pr::run(dry_run, json),
Cmd::Release { tag } => ops::release::run(tag.as_deref()),
Cmd::Setup { targets } => ops::tasks_cmd::run(ops::tasks_cmd::Task::Setup, false, &targets),
Cmd::Lint { force, targets } => {
ops::tasks_cmd::run(ops::tasks_cmd::Task::Lint, force, &targets)
}
Cmd::Test { force, targets } => {
ops::tasks_cmd::run(ops::tasks_cmd::Task::Test, force, &targets)
}
Cmd::Check {
dirty: _,
all,
json,
targets,
} => ops::check::run(json, all, &targets),
Cmd::Import { manifest } => ops::import::run(&manifest),
Cmd::Adopt {
plan,
step,
into,
normalize_branch,
standalone,
json,
yes,
dry_run,
} => {
if let Some(repo) = step {
ops::adopt::step(
&repo,
into.as_deref(),
normalize_branch.as_deref(),
standalone,
yes,
)
} else if plan {
ops::adopt::plan(json)
} else {
ops::adopt::run(yes, dry_run)
}
}
Cmd::Plan { json } => ops::plan::run(json),
Cmd::Next { json } => ops::plan::next(json),
Cmd::Rollup {
dry_run,
direct,
step,
from,
slug,
} => ops::rollup::run(dry_run, direct, step, from.as_deref(), slug.as_deref()),
}
}