diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bcfb390..05b8c67b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ![push](assets/push.gif) +- new branch list popup incl. checkout [[@WizardOhio24](https://github.com/timaliberdov)] ([#303](https://github.com/extrawurst/gitui/issues/303)) + - scrollbar in long commit messages [[@timaliberdov](https://github.com/timaliberdov)] ([#308](https://github.com/extrawurst/gitui/issues/308)) ### Changed diff --git a/asyncgit/src/sync/branch.rs b/asyncgit/src/sync/branch.rs index ab172cf6..9fe530fb 100644 --- a/asyncgit/src/sync/branch.rs +++ b/asyncgit/src/sync/branch.rs @@ -43,13 +43,13 @@ pub struct BranchForDisplay { pub is_head: bool, } -/// TODO make this cached /// Used to return only the nessessary information for displaying a branch /// rather than an iterator over the actual branches pub fn get_branches_to_display( repo_path: &str, ) -> Result> { scope_time!("get_branches_to_display"); + let cur_repo = utils::repo(repo_path)?; let mut branches_for_display = vec![]; @@ -65,7 +65,7 @@ pub fn get_branches_to_display( branch.get().name_bytes(), ))?, top_commit_message: String::from_utf8(Vec::from( - top_commit.summary_bytes().unwrap_or(&[]), + top_commit.summary_bytes().unwrap_or_default(), ))?, top_commit_reference: commit_id, is_head: branch.is_head(), @@ -80,31 +80,29 @@ pub fn checkout_branch( branch_ref: &str, ) -> Result<()> { scope_time!("checkout_branch"); + // This defaults to a safe checkout, so don't delete anything that // hasn't been committed or stashed, in this case it will Err let repo = utils::repo(repo_path)?; let cur_ref = repo.head()?; - if repo - .statuses(Some( - git2::StatusOptions::new().include_ignored(false), - ))? - .is_empty() - { + let statuses = repo.statuses(Some( + git2::StatusOptions::new().include_ignored(false), + ))?; + + if statuses.is_empty() { repo.set_head(branch_ref)?; if let Err(e) = repo.checkout_head(Some( git2::build::CheckoutBuilder::new().force(), )) { // This is safe beacuse cur_ref was just found - repo.set_head(cur_ref.name().unwrap_or(""))?; + repo.set_head(cur_ref.name().expect("utf8 error"))?; return Err(Error::Git(e)); } Ok(()) } else { Err(Error::Generic( - format!("Cannot change branch. There are unstaged/staged changes which have not been committed/stashed. There is {:?} changes preventing checking out a different branch.", repo.statuses(Some( - git2::StatusOptions::new().include_ignored(false), - ))?.len()), + format!("Cannot change branch. There are unstaged/staged changes which have not been committed/stashed. There is {:?} changes preventing checking out a different branch.", statuses.len()), )) } }