Skip to content

Commit 806085f

Browse files
committed
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.
1 parent fa39c09 commit 806085f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/git.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Repository {
158158
repo.remote_with_fetch(
159159
name,
160160
url,
161-
&format!("refs/heads/master:refs/remotes/{}/master", name),
161+
&format!("+refs/heads/master:refs/remotes/{}/master", name),
162162
)
163163
})
164164
.clone(
@@ -261,7 +261,11 @@ impl Repository {
261261
let mut origin = self.repository.find_remote("origin")?;
262262
let original_head = self.head_oid()?;
263263
origin.fetch(
264-
&["refs/heads/*:refs/heads/*"],
264+
// Force overwrite (`+` prefix) local master branch with the server's master branch.
265+
// The git CLI will refuse to fetch into the current branch of a non-bare repo
266+
// but libgit2 doesn't seem to prevent this potential footgun.
267+
// The entire point is to do a hard reset, so this footgun is not a concern.
268+
&["+refs/heads/master:refs/heads/master"],
265269
Some(&mut Self::fetch_options(&self.credentials)),
266270
None,
267271
)?;

0 commit comments

Comments
 (0)