From 98ec0eb9370bd12225fde1d8c2ff8b8ace693609 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 24 Jun 2021 20:51:31 +0200 Subject: git::mirror(): Change HEAD to GitHub default branch The default branch after mirroring was typically 'master'. On GitHub, the default branch may not necessarily be 'master'. Change the default branch by changing the HEAD to GitHub's default branch so that the mirrored repository better matches GitHub. We'll also need to make a change to the update function in case the default branch changes after mirroring. --- src/git.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index ac950e5..753137c 100644 --- a/src/git.rs +++ b/src/git.rs @@ -44,6 +44,7 @@ pub fn mirror>( url: &str, path: P, description: &str, + default_branch: &str, ) -> Result<(), Error> { let repo = git2::Repository::init_opts( path, @@ -74,6 +75,12 @@ pub fn mirror>( let refspecs: [&str; 0] = []; remote.fetch(&refspecs, None, None)?; + if default_branch != "master" { + repo.set_head( + &format!("refs/heads/{}", default_branch), + )?; + } + Ok(()) } -- cgit v1.2.3