ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: when exporting Git HEAD, use right workspace's new checkout (#13)

If the workspace is shared with a Git repo, we sometimes update Git's
HEAD ref. We should get the new checkout from the right workspace ID
when doing that (though I'm not sure we'll ever support sharing the
working copy with Git in a non-default workspace).
This commit is contained in:
Martin von Zweigbergk 2022-01-30 21:53:24 -08:00
parent 72b5d9a8c5
commit ee641bf7ad

View file

@ -319,16 +319,22 @@ impl WorkspaceCommandHelper {
.ok()
.map(|commit| commit.id());
git::export_refs(repo, &git_repo)?;
let checkout_id = repo.view().checkout();
let first_parent_id =
repo.index().entry_by_id(checkout_id).unwrap().parents()[0].commit_id();
if first_parent_id != *repo.store().root_commit_id() {
if let Some(current_git_commit_id) = current_git_commit_id {
git_repo.set_head_detached(current_git_commit_id)?;
if let Some(checkout_id) = repo.view().get_checkout(&self.workspace_id()) {
let first_parent_id =
repo.index().entry_by_id(checkout_id).unwrap().parents()[0].commit_id();
if first_parent_id != *repo.store().root_commit_id() {
if let Some(current_git_commit_id) = current_git_commit_id {
git_repo.set_head_detached(current_git_commit_id)?;
}
let new_git_commit_id = Oid::from_bytes(first_parent_id.as_bytes()).unwrap();
let new_git_commit = git_repo.find_commit(new_git_commit_id)?;
git_repo.reset(new_git_commit.as_object(), git2::ResetType::Mixed, None)?;
}
let new_git_commit_id = Oid::from_bytes(first_parent_id.as_bytes()).unwrap();
let new_git_commit = git_repo.find_commit(new_git_commit_id)?;
git_repo.reset(new_git_commit.as_object(), git2::ResetType::Mixed, None)?;
} else {
// The workspace was removed (maybe the user undid the
// initialization of the workspace?), which is weird,
// but we should probably just not do anything else here.
// Except maybe print a note about it?
}
Ok(())
}