fix hirarchical branch names (#931)

This commit is contained in:
Stephan Dilly 2021-10-06 10:50:57 +02:00 committed by GitHub
parent 8596e01dcd
commit c6abbaf4d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 2 deletions

View file

@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- support rebasing branches with conflicts ([#895](https://github.com/extrawurst/gitui/issues/895))
## Fixed
- appropriate error message when pulling deleted remote branch ([#911](https://github.com/extrawurst/gitui/issues/991))
- fix supported checkout of hierarchical branchnames ([#921](https://github.com/extrawurst/gitui/issues/921))
- appropriate error message when pulling deleted remote branch ([#911](https://github.com/extrawurst/gitui/issues/911))
- improved color contrast in branches popup for light themes [[@Cottser](https://github.com/Cottser)] ([#922](https://github.com/extrawurst/gitui/issues/922))
- use git_message_prettify for commit messages ([#917](https://github.com/extrawurst/gitui/issues/917))

View file

@ -319,7 +319,7 @@ pub fn checkout_remote_branch(
return Err(Error::UncommittedChanges);
}
let name = branch.name.rfind('/').map_or_else(
let name = branch.name.find('/').map_or_else(
|| branch.name.clone(),
|pos| branch.name[pos..].to_string(),
);
@ -795,6 +795,52 @@ mod test_remote_branches {
assert_eq!(&get_branch_name(clone2_dir).unwrap(), "foo");
}
#[test]
fn test_checkout_remote_branch_hirachical() {
let (r1_dir, _repo) = repo_init_bare().unwrap();
let (clone1_dir, clone1) =
repo_clone(r1_dir.path().to_str().unwrap()).unwrap();
let clone1_dir = clone1_dir.path().to_str().unwrap();
// clone1
let branch_name = "bar/foo";
write_commit_file(&clone1, "test.txt", "test", "commit1");
push(
clone1_dir, "origin", "master", false, false, None, None,
)
.unwrap();
create_branch(clone1_dir, branch_name).unwrap();
write_commit_file(&clone1, "test.txt", "test2", "commit2");
push(
clone1_dir,
"origin",
branch_name,
false,
false,
None,
None,
)
.unwrap();
// clone2
let (clone2_dir, _clone2) =
repo_clone(r1_dir.path().to_str().unwrap()).unwrap();
let clone2_dir = clone2_dir.path().to_str().unwrap();
let branches = get_branches_info(clone2_dir, false).unwrap();
checkout_remote_branch(clone2_dir, &branches[1]).unwrap();
assert_eq!(
&get_branch_name(clone2_dir).unwrap(),
branch_name
);
}
#[test]
fn test_has_tracking() {
let (r1_dir, _repo) = repo_init_bare().unwrap();