Skip to content

Commit

Permalink
Extract check for CLI to higher level
Browse files Browse the repository at this point in the history
  • Loading branch information
rpschoenburg committed Jan 8, 2025
1 parent abefbfd commit e8a2582
Show file tree
Hide file tree
Showing 50 changed files with 529 additions and 522 deletions.
3 changes: 2 additions & 1 deletion src/cli/src/cmd/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ impl RunCmd for AddCmd {
paths,
is_remote: false,
directory: None,
is_cli: true,
};

// Recursively look up from the current dir for .oxen directory
let repository = LocalRepository::from_current_dir()?;
check_repo_migration_needed(&repository)?;

for path in &opts.paths {
repositories::add(&repository, path)?;
repositories::add(&repository, path, true)?;
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/cli/src/cmd/workspace/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl RunCmd for WorkspaceAddCmd {
paths,
is_remote: false,
directory: None,
is_cli: true,
};

let repository = LocalRepository::from_current_dir()?;
Expand Down
30 changes: 15 additions & 15 deletions src/lib/src/api/client/branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mod tests {
// add and commit a file
let new_file = local_repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&local_repo, new_file)?;
repositories::add(&local_repo, new_file, false)?;
repositories::commit(&local_repo, "Added a new file")?;

// set proper remote
Expand All @@ -295,7 +295,7 @@ mod tests {
// add and commit a file
let new_file = local_repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&local_repo, new_file)?;
repositories::add(&local_repo, new_file, false)?;
repositories::commit(&local_repo, "Added a new file")?;

// set proper remote
Expand Down Expand Up @@ -324,7 +324,7 @@ mod tests {
// add and commit a file
let new_file = local_repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&local_repo, new_file)?;
repositories::add(&local_repo, new_file, false)?;
repositories::commit(&local_repo, "Added a new file")?;

// set proper remote
Expand Down Expand Up @@ -353,7 +353,7 @@ mod tests {
// add a file
let new_file = local_repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&local_repo, new_file)?;
repositories::add(&local_repo, new_file, false)?;
repositories::commit(&local_repo, "Added a new file")?;

// Set proper remote
Expand Down Expand Up @@ -394,7 +394,7 @@ mod tests {
// add and commit a file
let new_file = local_repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&local_repo, new_file)?;
repositories::add(&local_repo, new_file, false)?;
repositories::commit(&local_repo, "Added a new file")?;

// set proper remote
Expand Down Expand Up @@ -434,7 +434,7 @@ mod tests {
// add and commit a file
let new_file = local_repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&local_repo, new_file)?;
repositories::add(&local_repo, new_file, false)?;
repositories::commit(&local_repo, "Added a new file")?;

// set proper remote
Expand Down Expand Up @@ -469,7 +469,7 @@ mod tests {
// add and commit a file
let new_file = repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&repo, new_file)?;
repositories::add(&repo, new_file, false)?;
repositories::commit(&repo, "Added a new file")?;

// Create and checkout branch
Expand Down Expand Up @@ -579,7 +579,7 @@ mod tests {
// add and commit a file
let new_file = repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&repo, new_file)?;
repositories::add(&repo, new_file, false)?;
repositories::commit(&repo, "Added a new file")?;

let branch_name = "my-branch";
Expand All @@ -601,7 +601,7 @@ mod tests {
// add and commit a file
let new_file = repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&repo, new_file)?;
repositories::add(&repo, new_file, false)?;
repositories::commit(&repo, "Added a new file")?;

let branch_name = "my-branch";
Expand All @@ -622,7 +622,7 @@ mod tests {
// add and commit a file
let new_file = repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&repo, new_file)?;
repositories::add(&repo, new_file, false)?;
repositories::commit(&repo, "Added a new file")?;

let og_branches = repositories::branches::list(&repo)?;
Expand All @@ -633,7 +633,7 @@ mod tests {

// Add another commit on this branch
let labels_path = repo.path.join("labels.txt");
repositories::add(&repo, labels_path)?;
repositories::add(&repo, labels_path, false)?;
repositories::commit(&repo, "adding initial labels file")?;

// Checkout main again
Expand Down Expand Up @@ -661,7 +661,7 @@ mod tests {
// add and commit a file
let new_file = repo.path.join("new_file.txt");
util::fs::write(&new_file, "I am a new file")?;
repositories::add(&repo, new_file)?;
repositories::add(&repo, new_file, false)?;
repositories::commit(&repo, "Added a new file")?;

let og_branches = repositories::branches::list(&repo)?;
Expand All @@ -672,7 +672,7 @@ mod tests {

// Add another commit on this branch
let labels_path = repo.path.join("labels.txt");
repositories::add(&repo, labels_path)?;
repositories::add(&repo, labels_path, false)?;
repositories::commit(&repo, "adding initial labels file")?;

// Checkout main again
Expand Down Expand Up @@ -717,7 +717,7 @@ mod tests {
// Now push a new commit
let labels_path = repo.path.join("labels.txt");
test::write_txt_file_to_path(&labels_path, "I am the labels file")?;
repositories::add(&repo, labels_path)?;
repositories::add(&repo, labels_path, false)?;
repositories::commit(&repo, "adding labels file")?;
repositories::push(&repo).await?;

Expand Down Expand Up @@ -833,7 +833,7 @@ mod tests {

// Modify annotations file with new line
test::append_line_txt_file(&file_repo_path, "test/new_image.jpg,unknown,1.0,1.0,1,1")?;
repositories::add(&repo, &file_repo_path)?;
repositories::add(&repo, &file_repo_path, false)?;
let commit_2 = repositories::commit(&repo, "adding new annotation")?;

// Push to remote
Expand Down
8 changes: 4 additions & 4 deletions src/lib/src/api/client/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,12 +1357,12 @@ mod tests {
// test/
// annotations.txt
let train_dir = local_repo.path.join("annotations").join("train");
repositories::add(&local_repo, &train_dir)?;
repositories::add(&local_repo, &train_dir, false)?;
// Commit the directory
let commit1 = repositories::commit(&local_repo, "Adding 1")?;

let test_dir = local_repo.path.join("annotations").join("test");
repositories::add(&local_repo, &test_dir)?;
repositories::add(&local_repo, &test_dir, false)?;
// Commit the directory
let commit2 = repositories::commit(&local_repo, "Adding 2")?;

Expand Down Expand Up @@ -1436,7 +1436,7 @@ mod tests {
// test/
// annotations.txt
let annotations_dir = local_repo.path.join("annotations");
repositories::add(&local_repo, &annotations_dir)?;
repositories::add(&local_repo, &annotations_dir, false)?;
// Commit the directory
let commit = repositories::commit(
&local_repo,
Expand Down Expand Up @@ -1689,7 +1689,7 @@ mod tests {
// Add and commit a new file
let file_path = local_repo.path.join("test.txt");
let file_path = test::write_txt_file_to_path(file_path, "image,label\n1,2\n3,4\n5,6")?;
repositories::add(&local_repo, &file_path)?;
repositories::add(&local_repo, &file_path, false)?;
let commit = repositories::commit(&local_repo, "test")?;
let commit_hash = MerkleHash::from_str(&commit.id)?;

Expand Down
16 changes: 8 additions & 8 deletions src/lib/src/api/client/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mod tests {
local_repo.path.join(file_path),
format!("File content {}", i),
)?;
repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;

let commit_message = format!("Commit {}", i);
let commit = repositories::commit(&local_repo, &commit_message)?;
Expand Down Expand Up @@ -266,7 +266,7 @@ mod tests {
let full_path = &local_repo.path.join(file_path);

test::write_txt_file_to_path(full_path, "i am the contents of test_me_out.txt")?;
repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;

let commit_message = "add test_me_out.txt";
let new_commit = repositories::commit(&local_repo, commit_message)?;
Expand Down Expand Up @@ -317,14 +317,14 @@ mod tests {
let full_path = &local_repo.path.join(file_path);

test::write_txt_file_to_path(full_path, "image,label\n1,2\n3,4\n5,6")?;
repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;

let commit_message = "add test_me_out.csv";
let og_commit = repositories::commit(&local_repo, commit_message)?;

// Add another row
test::write_txt_file_to_path(full_path, "image,label\n1,2\n3,4\n5,6\n7,8")?;
repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;
let new_commit = repositories::commit(&local_repo, commit_message)?;

// Set remote
Expand Down Expand Up @@ -413,7 +413,7 @@ mod tests {
util::fs::create_dir_all(full_path.parent().unwrap())?;

test::write_txt_file_to_path(full_path, format!("File content {}", i))?;
repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;

let commit_message = format!("Commit {}", i);
let commit = repositories::commit(&local_repo, &commit_message)?;
Expand Down Expand Up @@ -460,7 +460,7 @@ mod tests {
test::write_txt_file_to_path(local_repo.path.join(left_path), csv1)?;
test::write_txt_file_to_path(local_repo.path.join(right_path), csv2)?;

repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;

repositories::commit(&local_repo, "committing files")?;

Expand Down Expand Up @@ -561,7 +561,7 @@ mod tests {
test::write_txt_file_to_path(local_repo.path.join(left_path), csv1)?;
test::write_txt_file_to_path(local_repo.path.join(right_path), csv2)?;

repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;
repositories::commit(&local_repo, "committing files")?;

// set remote
Expand Down Expand Up @@ -646,7 +646,7 @@ mod tests {
// let csv2 = "a,b,c,d\n1,2,3,4\n4,5,6,8\n0,1,9,2";

test::write_txt_file_to_path(local_repo.path.join(left_path), csv1)?;
repositories::add(&local_repo, &local_repo.path)?;
repositories::add(&local_repo, &local_repo.path, false)?;
repositories::commit(&local_repo, "committing files")?;
repositories::push(&local_repo).await?;

Expand Down
16 changes: 8 additions & 8 deletions src/lib/src/api/client/data_frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod tests {
let from_file = test::test_200k_csv();
util::fs::copy(from_file, &csv_file)?;

repositories::add(&local_repo, &csv_file)?;
repositories::add(&local_repo, &csv_file, false)?;
repositories::commit(&local_repo, "add test.csv")?;

// Add some metadata to the schema
Expand Down Expand Up @@ -206,7 +206,7 @@ mod tests {
let from_file = test::test_200k_csv();
util::fs::copy(from_file, &csv_file)?;

repositories::add(&local_repo, &csv_file)?;
repositories::add(&local_repo, &csv_file, false)?;
repositories::commit(&local_repo, "add test.csv")?;

// Set the proper remote
Expand Down Expand Up @@ -254,7 +254,7 @@ mod tests {
let from_file = test::test_200k_csv();
util::fs::copy(from_file, &csv_file)?;

repositories::add(&local_repo, &csv_file)?;
repositories::add(&local_repo, &csv_file, false)?;
repositories::commit(&local_repo, "add test.csv")?;

// Set the proper remote
Expand Down Expand Up @@ -308,7 +308,7 @@ mod tests {
let from_file = test::test_200k_csv();
util::fs::copy(from_file, &csv_file)?;

repositories::add(&local_repo, &csv_file)?;
repositories::add(&local_repo, &csv_file, false)?;
repositories::commit(&local_repo, "add test.csv")?;

// Set the proper remote
Expand Down Expand Up @@ -400,7 +400,7 @@ mod tests {
util::fs::copy(from_file, &csv_file)?;

// Add the file
repositories::add(&local_repo, &csv_file)?;
repositories::add(&local_repo, &csv_file, false)?;
repositories::commit(&local_repo, "add test.csv")?;

// Set the proper remote
Expand Down Expand Up @@ -510,7 +510,7 @@ mod tests {
let from_file = test::test_1k_parquet();
util::fs::copy(from_file, &test_file)?;

repositories::add(&local_repo, &test_file)?;
repositories::add(&local_repo, &test_file, false)?;
repositories::commit(&local_repo, "add test.parquet")?;

// Set the proper remote
Expand Down Expand Up @@ -577,7 +577,7 @@ mod tests {
let from_file = test::test_1k_parquet();
util::fs::copy(from_file, &test_file)?;

repositories::add(&local_repo, &test_file)?;
repositories::add(&local_repo, &test_file, false)?;
repositories::commit(&local_repo, "add test.parquet")?;

// Set the proper remote
Expand Down Expand Up @@ -640,7 +640,7 @@ mod tests {
let from_file = test::test_1k_parquet();
util::fs::copy(from_file, &test_file)?;

repositories::add(&local_repo, &test_file)?;
repositories::add(&local_repo, &test_file, false)?;
repositories::commit(&local_repo, "add test.parquet")?;

// Set the proper remote
Expand Down
Loading

0 comments on commit e8a2582

Please sign in to comment.