Fetch only the master branch when doing a hard reset
This avoids fetching the snapshot branches. The `+` prefix is added to
the refspec to ensure that the ref is updated even if it isn't a
fast-forward.
@@ -158,7 +158,7 @@ impl Repository {
repo.remote_with_fetch(
name,
url,
- &format!("refs/heads/master:refs/remotes/{}/master", name),
+ &format!("+refs/heads/master:refs/remotes/{}/master", name),
)
})
.clone(
@@ -261,7 +261,11 @@ impl Repository {
let mut origin = self.repository.find_remote("origin")?;
let original_head = self.head_oid()?;
origin.fetch(
- &["refs/heads/*:refs/heads/*"],
+ // Force overwrite (`+` prefix) local master branch with the server's master branch.
+ // The git CLI will refuse to fetch into the current branch of a non-bare repo
+ // but libgit2 doesn't seem to prevent this potential footgun.
+ // The entire point is to do a hard reset, so this footgun is not a concern.
+ &["+refs/heads/master:refs/heads/master"],
Some(&mut Self::fetch_options(&self.credentials)),
None,
)?;
