some docs and fixups

This commit is contained in:
Scott Chacon 2024-03-01 15:25:20 +01:00
parent 77e07e2308
commit 748630b262
3 changed files with 17 additions and 28 deletions

View File

@ -347,10 +347,9 @@ pub async fn reset_files(handle: AppHandle, project_id: &str, files: &str) -> Re
})?;
// convert files to Vec<String>
let files = files
.split("\n")
.map(|s| s.to_string())
.split('\n')
.map(std::string::ToString::to_string)
.collect::<Vec<String>>();
dbg!(files.clone());
handle
.state::<Controller>()
.reset_files(&project_id, &files)

View File

@ -749,8 +749,8 @@ impl ControllerInner {
) -> Result<(), ControllerError<errors::UnapplyOwnershipError>> {
let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |gb_repository, project_repository, _| {
super::reset_files(gb_repository, project_repository, ownership).map_err(Into::into)
self.with_verify_branch(project_id, |_, project_repository, _| {
super::reset_files(project_repository, ownership).map_err(Into::into)
})
}

View File

@ -565,12 +565,11 @@ pub fn unapply_ownership(
Ok(())
}
// reset a file in the project to the index state
pub fn reset_files(
gb_repository: &gb_repository::Repository,
project_repository: &project_repository::Repository,
files: &Vec<String>,
) -> Result<(), errors::UnapplyOwnershipError> {
dbg!("reset_files");
if conflicts::is_resolving(project_repository) {
return Err(errors::UnapplyOwnershipError::Conflict(
errors::ProjectConflictError {
@ -579,32 +578,23 @@ pub fn reset_files(
));
}
let repo = &project_repository.git_repository;
// for each tree, we need to checkout the entry from the index at that path
// or if it doesn't exist, remove the file from the working directory
let repo = &project_repository.git_repository;
let index = repo.index().context("failed to get index")?;
// put together a checkoutbuilder for each file
for file in files {
let entry = index.get_path(path::Path::new(file), 0);
match entry {
Some(entry) => {
dbg!(&entry);
repo.checkout_index_path(path::Path::new(file))
.context("failed to checkout index")?;
}
None => {
dbg!("new file, just delete it");
// find the project root
let project_root = &project_repository.project().path;
let path = path::Path::new(file);
//combine the project root with the file path
let path = &project_root.join(path);
std::fs::remove_file(&path).context("failed to remove file")?;
}
if let Some(entry) = entry {
repo.checkout_index_path(path::Path::new(file))
.context("failed to checkout index")?;
} else {
// find the project root
let project_root = &project_repository.project().path;
let path = path::Path::new(file);
//combine the project root with the file path
let path = &project_root.join(path);
std::fs::remove_file(path).context("failed to remove file")?;
}
dbg!(file);
}
Ok(())