aboutsummaryrefslogtreecommitdiffstats
path: root/src/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/git.rs b/src/git.rs
index 753137c..ccc0922 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -76,9 +76,7 @@ pub fn mirror<P: AsRef<Path>>(
remote.fetch(&refspecs, None, None)?;
if default_branch != "master" {
- repo.set_head(
- &format!("refs/heads/{}", default_branch),
- )?;
+ repo_change_current_branch(&repo, default_branch)?;
}
Ok(())
@@ -133,3 +131,28 @@ pub fn update_description<P: AsRef<Path>>(
Ok(())
}
+
+/// Change the current branch of the repository at `repo_path` to
+/// `default_branch`.
+pub fn change_current_branch<P: AsRef<Path>>(
+ repo_path: P,
+ default_branch: &str,
+) -> Result<(), Error> {
+ let repo = git2::Repository::open_bare(repo_path)?;
+
+ Ok(
+ repo_change_current_branch(&repo, default_branch)?
+ )
+}
+
+/// Change `repo`'s current branch to `default_branch`.
+fn repo_change_current_branch(
+ repo: &git2::Repository,
+ default_branch: &str,
+) -> Result<(), Error> {
+ Ok(
+ repo.set_head(
+ &format!("refs/heads/{}", default_branch),
+ )?
+ )
+}