Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions crates/edit_prediction_cli/src/example.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::paths::WORKTREES_DIR;
use crate::{PredictionProvider, PromptFormat};
use anyhow::{Context as _, Result};
use collections::HashMap;
Expand Down Expand Up @@ -90,7 +91,7 @@ pub struct ExampleScore {
}

impl Example {
pub fn repo_name(&self) -> Result<(Cow<'_, str>, Cow<'_, str>)> {
pub fn repo_name(&self) -> Result<RepoName<'_>> {
// git@github.com:owner/repo.git
if self.spec.repository_url.contains('@') {
let (owner, repo) = self
Expand All @@ -101,10 +102,10 @@ impl Example {
.1
.split_once('/')
.context("expected / in git url")?;
Ok((
Cow::Borrowed(owner),
Cow::Borrowed(repo.trim_end_matches(".git")),
))
Ok(RepoName {
owner: Cow::Borrowed(owner),
name: Cow::Borrowed(repo.trim_end_matches(".git")),
})
// https://github.com/owner/repo.git
} else {
let url = Url::parse(&self.spec.repository_url)?;
Expand All @@ -120,11 +121,27 @@ impl Example {
.to_string();
assert!(segments.next().is_none());

Ok((owner.into(), repo.into()))
Ok(RepoName {
owner: Cow::Owned(owner),
name: Cow::Owned(repo),
})
}
}
}

pub struct RepoName<'a> {
pub owner: Cow<'a, str>,
pub name: Cow<'a, str>,
}

impl RepoName<'_> {
pub fn worktree_path(&self) -> PathBuf {
WORKTREES_DIR
.join(self.owner.as_ref())
.join(self.name.as_ref())
}
}

pub fn read_example_files(inputs: &[PathBuf]) -> Vec<Example> {
let mut examples = Vec::new();

Expand Down
9 changes: 3 additions & 6 deletions crates/edit_prediction_cli/src/load_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{
example::{Example, ExampleBuffer, ExampleState},
git,
headless::EpAppState,
paths::WORKTREES_DIR,
progress::{InfoStyle, Progress, Step, StepProgress},
};
use anyhow::{Context as _, Result};
Expand Down Expand Up @@ -187,15 +186,13 @@ async fn setup_project(
}

async fn setup_worktree(example: &Example, step_progress: &StepProgress) -> Result<PathBuf> {
let (repo_owner, repo_name) = example.repo_name().context("failed to get repo name")?;
let repo_name = example.repo_name().context("failed to get repo name")?;
let repo_dir = git::repo_path_for_url(&example.spec.repository_url)?;
let worktree_path = WORKTREES_DIR
.join(repo_owner.as_ref())
.join(repo_name.as_ref());
let worktree_path = repo_name.worktree_path();
let repo_lock = git::lock_repo(&repo_dir).await;

if !repo_dir.is_dir() {
step_progress.set_substatus(format!("cloning {}", repo_name));
step_progress.set_substatus(format!("cloning {}", repo_name.name));
fs::create_dir_all(&repo_dir)?;
git::run_git(&repo_dir, &["init"]).await?;
git::run_git(
Expand Down
9 changes: 9 additions & 0 deletions crates/edit_prediction_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ fn main() {
.await
.unwrap();

let file_path = example
.repo_name()
.unwrap()
.worktree_path()
.join(&example.spec.cursor_path);

let msg = format!(
indoc::indoc! {"
While processing \"{}\":
Expand All @@ -441,6 +447,8 @@ fn main() {

Written to: \x1b[36m{}\x1b[0m

Cursor File: \x1b[36m{}\x1b[0m

Explore this example data with:
fx \x1b[36m{}\x1b[0m

Expand All @@ -450,6 +458,7 @@ fn main() {
example.spec.name,
e,
err_path.display(),
file_path.display(),
failed_example_path.display(),
command,
failed_example_path.display(),
Expand Down