Skip to content

Commit ecaccd2

Browse files
committed
Test detached head with force flag
So long as the detached head isn't pointed to by another branch, the --force flag will cause staged changes to be committed.
1 parent cb2ffa1 commit ecaccd2

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,27 @@ mod tests {
645645
assert!(is_something_in_index);
646646
}
647647

648+
#[test]
649+
fn detached_head_with_force_flag() {
650+
let ctx = repo_utils::prepare_and_stage();
651+
repo_utils::detach_head(&ctx);
652+
repo_utils::delete_branch(&ctx.repo, "master");
653+
654+
// run 'git-absorb'
655+
let drain = slog::Discard;
656+
let logger = slog::Logger::root(drain, o!());
657+
let config = Config {
658+
force: true,
659+
..DEFAULT_CONFIG
660+
};
661+
run_with_repo(&logger, &config, &ctx.repo).unwrap();
662+
let mut revwalk = ctx.repo.revwalk().unwrap();
663+
revwalk.push_head().unwrap();
664+
665+
assert_eq!(revwalk.count(), 3);
666+
assert!(nothing_left_in_index(&ctx.repo).unwrap());
667+
}
668+
648669
#[test]
649670
fn attached_head_pointing_at_commit_on_a_second_branch() {
650671
let ctx = repo_utils::prepare_and_stage();

src/tests/repo_utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,11 @@ pub fn add_branch(repo: &git2::Repository, branch_name: &str) {
9696
let head_commit = head.peel_to_commit().unwrap();
9797
repo.branch(branch_name, &head_commit, false).unwrap();
9898
}
99+
100+
/// Delete the branch with the given name.
101+
pub fn delete_branch(repo: &git2::Repository, branch_name: &str) {
102+
let mut branch = repo
103+
.find_branch(branch_name, git2::BranchType::Local)
104+
.unwrap();
105+
branch.delete().unwrap();
106+
}

0 commit comments

Comments
 (0)