mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
parent
94bbf3c9fb
commit
06aeca59d2
2 changed files with 12 additions and 12 deletions
|
|
@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||

|
||||
|
||||
- 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
|
||||
|
|
|
|||
|
|
@ -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<Vec<BranchForDisplay>> {
|
||||
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()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue