Skip to content

Commit

Permalink
git: make update_git_head accept an expected ref
Browse files Browse the repository at this point in the history
This change will allow `update_git_head` to be used in `reset_head`.
  • Loading branch information
scott2000 committed Jan 7, 2025
1 parent d859a91 commit 3f72604
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,11 @@ pub fn export_some_refs(
current_oid.as_ref()
};
if new_oid != current_oid.as_ref() {
update_git_head(&git_repo, old_target, current_oid)?;
update_git_head(
&git_repo,
gix::refs::transaction::PreviousValue::MustExistAndMatch(old_target),
current_oid,
)?;
}
}
}
Expand Down Expand Up @@ -942,7 +946,7 @@ fn update_git_ref(
/// is `None` (meaning absent), dummy placeholder ref will be set.
fn update_git_head(
git_repo: &gix::Repository,
old_target: gix::refs::Target,
expected_ref: gix::refs::transaction::PreviousValue,
new_oid: Option<gix::ObjectId>,
) -> Result<(), GitExportError> {
let mut ref_edits = Vec::new();
Expand All @@ -969,7 +973,7 @@ fn update_git_head(
message: "export from jj".into(),
..Default::default()
},
expected: gix::refs::transaction::PreviousValue::MustExistAndMatch(old_target),
expected: expected_ref,
new: new_target,
},
name: "HEAD".try_into().unwrap(),
Expand Down

0 comments on commit 3f72604

Please sign in to comment.