Skip to content

Commit

Permalink
Don't deviate by creating strange reflogs (with null-source & null-de…
Browse files Browse the repository at this point in the history
…stination) (#450)

That's exactly what git does, so it's probably the right thing to do if
in doubt.
  • Loading branch information
Byron committed Nov 2, 2022
1 parent 619fd61 commit f1b5570
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
5 changes: 0 additions & 5 deletions git-repository/src/clone/fetch/mod.rs
Expand Up @@ -41,11 +41,6 @@ impl PrepareFetch {
/// it was newly initialized.
///
/// Note that all data we created will be removed once this instance drops if the operation wasn't successful.
///
/// # Deviation
///
/// When the remote side is freshly initialized without commits, we pick up their reference name _and_ create a reflog entry like
/// before, with old and new hash being the `null-hex-sha`. That way the branch still remembers where it was created from.
#[cfg(feature = "blocking-network-client")]
pub fn fetch_only<P>(
&mut self,
Expand Down
27 changes: 13 additions & 14 deletions git-repository/src/clone/fetch/util.rs
Expand Up @@ -117,20 +117,19 @@ pub fn update_head(
.commit(repo.committer_or_default())
.map_err(crate::reference::edit::Error::from)?;

let mut log = reflog_message();
log.mode = RefLog::Only;
repo.edit_reference(RefEdit {
change: git_ref::transaction::Change::Update {
log,
expected: PreviousValue::Any,
new: Target::Peeled(match head_peeled_id {
Some(id) => id.to_owned(),
None => git_hash::ObjectId::null(repo.object_hash()),
}),
},
name: head,
deref: false,
})?;
if let Some(head_peeled_id) = head_peeled_id {
let mut log = reflog_message();
log.mode = RefLog::Only;
repo.edit_reference(RefEdit {
change: git_ref::transaction::Change::Update {
log,
expected: PreviousValue::Any,
new: Target::Peeled(*head_peeled_id),
},
name: head,
deref: false,
})?;
}
}
None => {
repo.edit_reference(RefEdit {
Expand Down
6 changes: 4 additions & 2 deletions git-repository/tests/clone/mod.rs
Expand Up @@ -208,8 +208,10 @@ mod blocking_io {
let head = repo.head()?;
assert!(head.is_unborn());

let mut logs = head.log_iter();
assert_reflog(logs.all());
assert!(
head.log_iter().all()?.is_none(),
"no reflog for unborn heads (as it needs non-null destination hash)"
);

if out
.ref_map
Expand Down

0 comments on commit f1b5570

Please sign in to comment.