diff options
author | Teddy Wing | 2021-06-24 20:51:31 +0200 |
---|---|---|
committer | Teddy Wing | 2021-06-24 20:53:34 +0200 |
commit | 98ec0eb9370bd12225fde1d8c2ff8b8ace693609 (patch) | |
tree | 69f461278fed740aa6cfadbd4ac3ae506dc5f1f2 | |
parent | b3d87f44a9801ea84347dee764d21c0db8d87fbd (diff) | |
download | reflectub-98ec0eb9370bd12225fde1d8c2ff8b8ace693609.tar.bz2 |
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.
-rw-r--r-- | src/git.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 1 |
2 files changed, 8 insertions, 0 deletions
@@ -44,6 +44,7 @@ pub fn mirror<P: AsRef<Path>>( 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<P: AsRef<Path>>( let refspecs: [&str; 0] = []; remote.fetch(&refspecs, None, None)?; + if default_branch != "master" { + repo.set_head( + &format!("refs/heads/{}", default_branch), + )?; + } + Ok(()) } diff --git a/src/main.rs b/src/main.rs index 811dcb4..0fdc715 100644 --- a/src/main.rs +++ b/src/main.rs @@ -244,6 +244,7 @@ where &repo.git_url, &clone_path, repo.description(), + &repo.default_branch, )?; // Copy the base cgitrc file into the newly-cloned repository. |