@@ -817,6 +817,22 @@ impl Repository {
817
817
/// Otherwise, the HEAD will be detached and will directly point to the
818
818
/// commit.
819
819
pub fn set_head ( & self , refname : & str ) -> Result < ( ) , Error > {
820
+ self . set_head_bytes ( refname. as_bytes ( ) )
821
+ }
822
+
823
+ /// Make the repository HEAD point to the specified reference as a byte array.
824
+ ///
825
+ /// If the provided reference points to a tree or a blob, the HEAD is
826
+ /// unaltered and an error is returned.
827
+ ///
828
+ /// If the provided reference points to a branch, the HEAD will point to
829
+ /// that branch, staying attached, or become attached if it isn't yet. If
830
+ /// the branch doesn't exist yet, no error will be returned. The HEAD will
831
+ /// then be attached to an unborn branch.
832
+ ///
833
+ /// Otherwise, the HEAD will be detached and will directly point to the
834
+ /// commit.
835
+ pub fn set_head_bytes ( & self , refname : & [ u8 ] ) -> Result < ( ) , Error > {
820
836
let refname = CString :: new ( refname) ?;
821
837
unsafe {
822
838
try_call ! ( raw:: git_repository_set_head( self . raw, refname) ) ;
@@ -3602,6 +3618,19 @@ mod tests {
3602
3618
assert ! ( repo. set_head( "*" ) . is_err( ) ) ;
3603
3619
}
3604
3620
3621
+ #[ test]
3622
+ fn smoke_set_head_bytes ( ) {
3623
+ let ( _td, repo) = crate :: test:: repo_init ( ) ;
3624
+
3625
+ assert ! ( repo. set_head_bytes( b"refs/heads/does-not-exist" ) . is_ok( ) ) ;
3626
+ assert ! ( repo. head( ) . is_err( ) ) ;
3627
+
3628
+ assert ! ( repo. set_head_bytes( b"refs/heads/main" ) . is_ok( ) ) ;
3629
+ assert ! ( repo. head( ) . is_ok( ) ) ;
3630
+
3631
+ assert ! ( repo. set_head_bytes( b"*" ) . is_err( ) ) ;
3632
+ }
3633
+
3605
3634
#[ test]
3606
3635
fn smoke_set_head_detached ( ) {
3607
3636
let ( _td, repo) = crate :: test:: repo_init ( ) ;
0 commit comments