Skip to content

Commit

Permalink
assure the reflog settings aren't permanently overidden during init/f…
Browse files Browse the repository at this point in the history
…etch (#450)
  • Loading branch information
Byron committed Oct 17, 2022
1 parent bc991ff commit bc5e3e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions git-repository/src/clone/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ impl PrepareFetch {

/// HEAD cannot be written by means of refspec by design, so we have to do it manually here. Also create the pointed-to ref
/// if we have to, as it might not have been naturally included in the ref-specs.
fn update_head(repo: &mut Repository, remote_refs: &[git_protocol::fetch::Ref]) -> Result<(), Error> {
use git_ref::store::WriteReflog;
fn update_head(repo: &Repository, remote_refs: &[git_protocol::fetch::Ref]) -> Result<(), Error> {
use git_ref::transaction::{PreviousValue, RefEdit};
use git_ref::Target;
use std::convert::TryInto;
Expand All @@ -94,7 +93,6 @@ impl PrepareFetch {
})
.ok_or(Error::MissingRemoteHead)?;

repo.refs.write_reflog = WriteReflog::Disable;
let name = "HEAD".try_into().expect("valid");
match head_ref {
Some(referent) => {
Expand Down Expand Up @@ -179,7 +177,12 @@ impl PrepareFetch {
let outcome = pending_pack.receive(should_interrupt)?;

replace_changed_local_config(repo, config);
update_head(repo, &outcome.ref_map.remote_refs)?;

let prev_write_ref_log = repo.refs.write_reflog;
repo.refs.write_reflog = git_ref::store::WriteReflog::Disable;
let res = update_head(repo, &outcome.ref_map.remote_refs);
repo.refs.write_reflog = prev_write_ref_log;
res?;

Ok((self.repo.take().expect("still present"), outcome))
}
Expand Down
2 changes: 2 additions & 0 deletions git-repository/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl ThreadSafeRepository {
source: err,
})?;
let mut repo = repo.to_thread_local();
let prev_write_reflog = repo.refs.write_reflog;
repo.refs.write_reflog = WriteReflog::Disable;
repo.edit_reference(RefEdit {
change: git_ref::transaction::Change::Update {
Expand All @@ -83,6 +84,7 @@ impl ThreadSafeRepository {
name: "HEAD".try_into().expect("valid"),
deref: false,
})?;
repo.refs.write_reflog = prev_write_reflog;
}

Ok(repo)
Expand Down

0 comments on commit bc5e3e4

Please sign in to comment.