Skip to content

Commit f1b5570

Browse files
committed
Don't deviate by creating strange reflogs (with null-source & null-destination) (#450)
That's exactly what git does, so it's probably the right thing to do if in doubt.
1 parent 619fd61 commit f1b5570

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

git-repository/src/clone/fetch/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ impl PrepareFetch {
4141
/// it was newly initialized.
4242
///
4343
/// Note that all data we created will be removed once this instance drops if the operation wasn't successful.
44-
///
45-
/// # Deviation
46-
///
47-
/// When the remote side is freshly initialized without commits, we pick up their reference name _and_ create a reflog entry like
48-
/// before, with old and new hash being the `null-hex-sha`. That way the branch still remembers where it was created from.
4944
#[cfg(feature = "blocking-network-client")]
5045
pub fn fetch_only<P>(
5146
&mut self,

git-repository/src/clone/fetch/util.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,19 @@ pub fn update_head(
117117
.commit(repo.committer_or_default())
118118
.map_err(crate::reference::edit::Error::from)?;
119119

120-
let mut log = reflog_message();
121-
log.mode = RefLog::Only;
122-
repo.edit_reference(RefEdit {
123-
change: git_ref::transaction::Change::Update {
124-
log,
125-
expected: PreviousValue::Any,
126-
new: Target::Peeled(match head_peeled_id {
127-
Some(id) => id.to_owned(),
128-
None => git_hash::ObjectId::null(repo.object_hash()),
129-
}),
130-
},
131-
name: head,
132-
deref: false,
133-
})?;
120+
if let Some(head_peeled_id) = head_peeled_id {
121+
let mut log = reflog_message();
122+
log.mode = RefLog::Only;
123+
repo.edit_reference(RefEdit {
124+
change: git_ref::transaction::Change::Update {
125+
log,
126+
expected: PreviousValue::Any,
127+
new: Target::Peeled(*head_peeled_id),
128+
},
129+
name: head,
130+
deref: false,
131+
})?;
132+
}
134133
}
135134
None => {
136135
repo.edit_reference(RefEdit {

git-repository/tests/clone/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ mod blocking_io {
208208
let head = repo.head()?;
209209
assert!(head.is_unborn());
210210

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

214216
if out
215217
.ref_map

0 commit comments

Comments
 (0)