| 596 | |
| 597 | #[test] |
| 598 | fn test_target_branch() { |
| 599 | let dir = tempfile::tempdir().unwrap(); |
| 600 | let repo = git2::Repository::init_opts( |
| 601 | dir.path(), |
| 602 | git2::RepositoryInitOptions::new() |
| 603 | .initial_head("main") |
| 604 | .mkdir(false), |
| 605 | ) |
| 606 | .unwrap(); |
| 607 | let sig = git2::Signature::now("Test", "test@example.com").unwrap(); |
| 608 | let tree_oid = repo.index().unwrap().write_tree().unwrap(); |
| 609 | let tree = repo.find_tree(tree_oid).unwrap(); |
| 610 | repo.commit(Some("HEAD"), &sig, &sig, "init", &tree, &[]) |
| 611 | .unwrap(); |
| 612 | |
| 613 | // Default: the checked-out branch. |
| 614 | assert_eq!(Push::default().target_branch(&repo), "main"); |
| 615 | |
| 616 | // --branch wins. |
| 617 | let push = Push { |
| 618 | branch: Some("pr-42".to_string()), |
| 619 | ..Push::default() |
| 620 | }; |
| 621 | assert_eq!(push.target_branch(&repo), "pr-42"); |
| 622 | } |
| 623 | } |