File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments