diff --git a/src-tauri/src/bin/butler.rs b/src-tauri/src/bin/butler.rs index 06d0780dc..fb5064879 100644 --- a/src-tauri/src/bin/butler.rs +++ b/src-tauri/src/bin/butler.rs @@ -83,13 +83,20 @@ fn main() { fn run_clear(butler: ButlerCli) { // make sure there is a session - butler + let session = butler .gb_repository .get_or_create_current_session() .expect("failed to get or create currnt session"); - let branch_path = butler.gb_repository.branches_path(); - // delete 'butler' directory under path - std::fs::remove_dir_all(branch_path).unwrap(); + let session_reader = sessions::Reader::open(&butler.gb_repository, &session) + .expect("failed to open current session reader"); + let branch_writer = virtual_branches::branch::Writer::new(&butler.gb_repository); + let iterator = + virtual_branches::Iterator::new(&session_reader).expect("failed to read branches"); + for branch in iterator.flatten() { + branch_writer + .delete(&branch) + .unwrap_or_else(|e| panic!("failed to delete branch: {:?}", e)); + } } fn run_reset(butler: ButlerCli) { diff --git a/src-tauri/src/gb_repository/repository.rs b/src-tauri/src/gb_repository/repository.rs index 0b007b8c4..ee98efccb 100644 --- a/src-tauri/src/gb_repository/repository.rs +++ b/src-tauri/src/gb_repository/repository.rs @@ -541,10 +541,6 @@ impl Repository { self.git_repository.path().join("gitbutler") } - pub fn branches_path(&self) -> std::path::PathBuf { - self.root().join("branches") - } - pub(crate) fn session_path(&self) -> std::path::PathBuf { self.root().join("session") } diff --git a/src-tauri/src/project_repository/repository.rs b/src-tauri/src/project_repository/repository.rs index 543561fd6..b96601f5b 100644 --- a/src-tauri/src/project_repository/repository.rs +++ b/src-tauri/src/project_repository/repository.rs @@ -1,7 +1,7 @@ use core::fmt; use std::{cell::Cell, collections::HashMap, env, io::Write, process::Command}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result}; use git2::{CredentialType, Diff}; use serde::Serialize; use std::io::BufRead; @@ -229,20 +229,6 @@ impl<'repository> Repository<'repository> { // end merge conflict state stuff - pub fn get_head_commit(&self) -> Result { - let repo = &self.git_repository; - let head = repo.head().context("failed to get head")?; - let name = head.name().unwrap(); - if name != "refs/heads/gitbutler/integration" { - bail!("we are no longer on our integration branch"); - } - let head_oid = head.target().context("failed to get head oid")?; - let head_commit = repo - .find_commit(head_oid) - .context("failed to find head commit")?; - Ok(head_commit) - } - pub fn git_status(&self) -> Result> { let staged_statuses = self.staged_statuses()?; let unstaged_statuses = self.unstaged_statuses()?;