feat: expose read-only local review CLI
This commit is contained in:
+24
-11
@@ -1091,22 +1091,35 @@ pub struct Repository {
|
||||
comparison: Option<PreparedComparison>,
|
||||
cancelled: Arc<AtomicBool>,
|
||||
}
|
||||
/// Discover the canonical checkout root without opening a comparison repository.
|
||||
pub fn discover_root(path: &Path) -> Result<PathBuf, String> {
|
||||
discover_root_with_cancellation(path, &AtomicBool::new(false))
|
||||
}
|
||||
|
||||
fn discover_root_with_cancellation(path: &Path, cancelled: &AtomicBool) -> Result<PathBuf, String> {
|
||||
let path = fs::canonicalize(path).map_err(|error| error.to_string())?;
|
||||
let root = path
|
||||
.ancestors()
|
||||
.find(|path| path.join(".jj").exists() || path.join(".git").exists())
|
||||
.ok_or("No Jujutsu or Git working-tree repository found")?;
|
||||
if root.join(".jj").exists() {
|
||||
let mut command = jj_command(root);
|
||||
command.arg("root");
|
||||
let output = checked(run(command, vec![], cancelled)?)?;
|
||||
let root = path_bytes(output.strip_suffix(b"\n").unwrap_or(&output))?;
|
||||
fs::canonicalize(root).map_err(|error| error.to_string())
|
||||
} else {
|
||||
Ok(root.to_path_buf())
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
pub fn open(root: &Path, cancelled: Arc<AtomicBool>) -> Result<Self, String> {
|
||||
let root = fs::canonicalize(root).map_err(|e| e.to_string())?;
|
||||
let discovered = root
|
||||
.ancestors()
|
||||
.find(|p| p.join(".jj").exists() || p.join(".git").exists())
|
||||
.ok_or("No Jujutsu or Git working-tree repository found")?;
|
||||
let (root, kind, store) = if discovered.join(".jj").exists() {
|
||||
let mut cmd = jj_command(discovered);
|
||||
cmd.arg("root");
|
||||
let output = checked(run(cmd, vec![], &cancelled)?)?;
|
||||
let actual = path_bytes(output.strip_suffix(b"\n").unwrap_or(&output))?;
|
||||
let actual = discover_root_with_cancellation(root, &cancelled)?;
|
||||
let (root, kind, store) = if actual.join(".jj").exists() {
|
||||
let store = store_for_jj(&actual)?;
|
||||
(actual, RepoKind::Jujutsu, store)
|
||||
} else {
|
||||
let actual = discovered.to_path_buf();
|
||||
let mut cmd = Command::new("git");
|
||||
cmd.arg("-C")
|
||||
.arg(&actual)
|
||||
|
||||
Reference in New Issue
Block a user