Skip to content

Commit

Permalink
some docs and fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
schacon committed Mar 1, 2024
1 parent 77e07e2 commit 748630b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
5 changes: 2 additions & 3 deletions gitbutler-app/src/virtual_branches/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions gitbutler-app/src/virtual_branches/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
36 changes: 13 additions & 23 deletions gitbutler-app/src/virtual_branches/virtual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(())
Expand Down

0 comments on commit 748630b

Please sign in to comment.