mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-14 02:07:22 +03:00
refs: add constructor of Some(RefTarget::Normal(id))
If RefTarget is migrated to new Conflict type, this function will create RefTarget(Conflict::resolved(Some(id))). We still need some .unwrap() to insert Option<RefTarget> into map, but maps will be changed to store new RefTarget type, and their mutation API will guarantee that Conflict::resolved(None) is eliminated.
This commit is contained in:
parent
e212e10dee
commit
e55c533add
@ -203,7 +203,7 @@ pub fn import_some_refs(
|
||||
let head_commit = store.get_commit(&head_commit_id).unwrap();
|
||||
prevent_gc(git_repo, &head_commit_id)?;
|
||||
mut_repo.add_head(&head_commit);
|
||||
mut_repo.set_git_head_target(Some(RefTarget::Normal(head_commit_id)));
|
||||
mut_repo.set_git_head_target(RefTarget::normal(head_commit_id));
|
||||
}
|
||||
} else {
|
||||
mut_repo.set_git_head_target(None);
|
||||
@ -240,10 +240,10 @@ pub fn import_some_refs(
|
||||
// TODO: Make it configurable which remotes are publishing and update public
|
||||
// heads here.
|
||||
let old_target = jj_view_git_refs.remove(full_name);
|
||||
let new_target = Some(RefTarget::Normal(id.clone()));
|
||||
let new_target = RefTarget::normal(id.clone());
|
||||
if new_target != old_target {
|
||||
prevent_gc(git_repo, &id)?;
|
||||
mut_repo.set_git_ref_target(full_name, Some(RefTarget::Normal(id.clone())));
|
||||
mut_repo.set_git_ref_target(full_name, RefTarget::normal(id.clone()));
|
||||
let commit = store.get_commit(&id).unwrap();
|
||||
mut_repo.add_head(&commit);
|
||||
changed_git_refs.insert(ref_name, (old_target, new_target));
|
||||
@ -511,7 +511,7 @@ pub fn export_some_refs(
|
||||
if success {
|
||||
mut_repo.set_git_ref_target(
|
||||
&git_ref_name,
|
||||
Some(RefTarget::Normal(CommitId::from_bytes(new_oid.as_bytes()))),
|
||||
RefTarget::normal(CommitId::from_bytes(new_oid.as_bytes())),
|
||||
);
|
||||
} else {
|
||||
failed_branches.push(parsed_ref_name);
|
||||
|
@ -143,6 +143,11 @@ impl ContentHash for RefTarget {
|
||||
}
|
||||
|
||||
impl RefTarget {
|
||||
/// Creates non-conflicting target pointing to a commit.
|
||||
pub fn normal(id: CommitId) -> Option<Self> {
|
||||
Some(RefTarget::Normal(id))
|
||||
}
|
||||
|
||||
pub fn is_conflict(&self) -> bool {
|
||||
matches!(self, RefTarget::Conflict { .. })
|
||||
}
|
||||
|
@ -171,9 +171,9 @@ mod tests {
|
||||
fn test_classify_branch_push_action_unchanged() {
|
||||
let commit_id1 = CommitId::from_hex("11");
|
||||
let branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(commit_id1.clone())),
|
||||
local_target: RefTarget::normal(commit_id1.clone()),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(commit_id1)
|
||||
"origin".to_string() => RefTarget::normal(commit_id1).unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -186,7 +186,7 @@ mod tests {
|
||||
fn test_classify_branch_push_action_added() {
|
||||
let commit_id1 = CommitId::from_hex("11");
|
||||
let branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(commit_id1.clone())),
|
||||
local_target: RefTarget::normal(commit_id1.clone()),
|
||||
remote_targets: btreemap! {},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -204,7 +204,7 @@ mod tests {
|
||||
let branch = BranchTarget {
|
||||
local_target: None,
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(commit_id1.clone())
|
||||
"origin".to_string() => RefTarget::normal(commit_id1.clone()).unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -221,9 +221,9 @@ mod tests {
|
||||
let commit_id1 = CommitId::from_hex("11");
|
||||
let commit_id2 = CommitId::from_hex("22");
|
||||
let branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(commit_id2.clone())),
|
||||
local_target: RefTarget::normal(commit_id2.clone()),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(commit_id1.clone())
|
||||
"origin".to_string() => RefTarget::normal(commit_id1.clone()).unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -245,7 +245,7 @@ mod tests {
|
||||
adds: vec![commit_id1.clone(), commit_id2],
|
||||
}),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(commit_id1)
|
||||
"origin".to_string() => RefTarget::normal(commit_id1).unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -259,7 +259,7 @@ mod tests {
|
||||
let commit_id1 = CommitId::from_hex("11");
|
||||
let commit_id2 = CommitId::from_hex("22");
|
||||
let branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(commit_id1.clone())),
|
||||
local_target: RefTarget::normal(commit_id1.clone()),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Conflict {
|
||||
removes: vec![],
|
||||
|
@ -320,7 +320,7 @@ fn view_from_proto(proto: crate::protos::op_store::View) -> View {
|
||||
if let Some(git_head) = proto.git_head.as_ref() {
|
||||
view.git_head = Some(ref_target_from_proto(git_head.clone()));
|
||||
} else if !proto.git_head_legacy.is_empty() {
|
||||
view.git_head = Some(RefTarget::Normal(CommitId::new(proto.git_head_legacy)));
|
||||
view.git_head = RefTarget::normal(CommitId::new(proto.git_head_legacy));
|
||||
}
|
||||
|
||||
view
|
||||
@ -382,11 +382,11 @@ mod tests {
|
||||
let head_id2 = CommitId::from_hex("aaa222");
|
||||
let public_head_id1 = CommitId::from_hex("bbb444");
|
||||
let public_head_id2 = CommitId::from_hex("bbb555");
|
||||
let branch_main_local_target = RefTarget::Normal(CommitId::from_hex("ccc111"));
|
||||
let branch_main_origin_target = RefTarget::Normal(CommitId::from_hex("ccc222"));
|
||||
let branch_deleted_origin_target = RefTarget::Normal(CommitId::from_hex("ccc333"));
|
||||
let tag_v1_target = RefTarget::Normal(CommitId::from_hex("ddd111"));
|
||||
let git_refs_main_target = RefTarget::Normal(CommitId::from_hex("fff111"));
|
||||
let branch_main_local_target = RefTarget::normal(CommitId::from_hex("ccc111"));
|
||||
let branch_main_origin_target = RefTarget::normal(CommitId::from_hex("ccc222"));
|
||||
let branch_deleted_origin_target = RefTarget::normal(CommitId::from_hex("ccc333"));
|
||||
let tag_v1_target = RefTarget::normal(CommitId::from_hex("ddd111"));
|
||||
let git_refs_main_target = RefTarget::normal(CommitId::from_hex("fff111"));
|
||||
let git_refs_feature_target = RefTarget::Conflict {
|
||||
removes: vec![CommitId::from_hex("fff111")],
|
||||
adds: vec![CommitId::from_hex("fff222"), CommitId::from_hex("fff333")],
|
||||
@ -398,26 +398,26 @@ mod tests {
|
||||
public_head_ids: hashset! {public_head_id1, public_head_id2},
|
||||
branches: btreemap! {
|
||||
"main".to_string() => BranchTarget {
|
||||
local_target: Some(branch_main_local_target),
|
||||
local_target: branch_main_local_target,
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => branch_main_origin_target,
|
||||
"origin".to_string() => branch_main_origin_target.unwrap(),
|
||||
}
|
||||
},
|
||||
"deleted".to_string() => BranchTarget {
|
||||
local_target: None,
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => branch_deleted_origin_target,
|
||||
"origin".to_string() => branch_deleted_origin_target.unwrap(),
|
||||
}
|
||||
},
|
||||
},
|
||||
tags: btreemap! {
|
||||
"v1.0".to_string() => tag_v1_target,
|
||||
"v1.0".to_string() => tag_v1_target.unwrap(),
|
||||
},
|
||||
git_refs: btreemap! {
|
||||
"refs/heads/main".to_string() => git_refs_main_target,
|
||||
"refs/heads/main".to_string() => git_refs_main_target.unwrap(),
|
||||
"refs/heads/feature".to_string() => git_refs_feature_target
|
||||
},
|
||||
git_head: Some(RefTarget::Normal(CommitId::from_hex("fff111"))),
|
||||
git_head: RefTarget::normal(CommitId::from_hex("fff111")),
|
||||
wc_commit_ids: hashmap! {
|
||||
WorkspaceId::default() => default_wc_commit_id,
|
||||
WorkspaceId::new("test".to_string()) => test_wc_commit_id,
|
||||
|
@ -109,9 +109,9 @@ fn test_import_refs() {
|
||||
assert_eq!(*view.heads(), expected_heads);
|
||||
|
||||
let expected_main_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit2))),
|
||||
local_target: RefTarget::normal(jj_id(&commit2)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&commit1)),
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&commit1)).unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -119,7 +119,7 @@ fn test_import_refs() {
|
||||
Some(expected_main_branch).as_ref()
|
||||
);
|
||||
let expected_feature1_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit3))),
|
||||
local_target: RefTarget::normal(jj_id(&commit3)),
|
||||
remote_targets: btreemap! {},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -127,7 +127,7 @@ fn test_import_refs() {
|
||||
Some(expected_feature1_branch).as_ref()
|
||||
);
|
||||
let expected_feature2_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit4))),
|
||||
local_target: RefTarget::normal(jj_id(&commit4)),
|
||||
remote_targets: btreemap! {},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -135,9 +135,9 @@ fn test_import_refs() {
|
||||
Some(expected_feature2_branch).as_ref()
|
||||
);
|
||||
let expected_feature3_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit6))),
|
||||
local_target: RefTarget::normal(jj_id(&commit6)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&commit6)),
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&commit6)).unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -147,35 +147,35 @@ fn test_import_refs() {
|
||||
|
||||
assert_eq!(
|
||||
view.tags().get("v1.0"),
|
||||
Some(RefTarget::Normal(jj_id(&commit5))).as_ref()
|
||||
RefTarget::normal(jj_id(&commit5)).as_ref()
|
||||
);
|
||||
|
||||
assert_eq!(view.git_refs().len(), 6);
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(jj_id(&commit2)))
|
||||
RefTarget::normal(jj_id(&commit2))
|
||||
);
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/heads/feature1"),
|
||||
Some(RefTarget::Normal(jj_id(&commit3)))
|
||||
RefTarget::normal(jj_id(&commit3))
|
||||
);
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/heads/feature2"),
|
||||
Some(RefTarget::Normal(jj_id(&commit4)))
|
||||
RefTarget::normal(jj_id(&commit4))
|
||||
);
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/remotes/origin/main"),
|
||||
Some(RefTarget::Normal(jj_id(&commit1)))
|
||||
RefTarget::normal(jj_id(&commit1))
|
||||
);
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/remotes/origin/feature3"),
|
||||
Some(RefTarget::Normal(jj_id(&commit6)))
|
||||
RefTarget::normal(jj_id(&commit6))
|
||||
);
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/tags/v1.0"),
|
||||
Some(RefTarget::Normal(jj_id(&commit5)))
|
||||
RefTarget::normal(jj_id(&commit5))
|
||||
);
|
||||
assert_eq!(view.git_head(), Some(&RefTarget::Normal(jj_id(&commit2))));
|
||||
assert_eq!(view.git_head(), RefTarget::normal(jj_id(&commit2)).as_ref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -220,7 +220,7 @@ fn test_import_refs_reimport() {
|
||||
.write()
|
||||
.unwrap();
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target("feature2", Some(RefTarget::Normal(commit6.id().clone())));
|
||||
.set_local_branch_target("feature2", RefTarget::normal(commit6.id().clone()));
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
@ -236,12 +236,12 @@ fn test_import_refs_reimport() {
|
||||
assert_eq!(*view.heads(), expected_heads);
|
||||
|
||||
assert_eq!(view.branches().len(), 2);
|
||||
let commit1_target = RefTarget::Normal(jj_id(&commit1));
|
||||
let commit2_target = RefTarget::Normal(jj_id(&commit2));
|
||||
let commit1_target = RefTarget::normal(jj_id(&commit1));
|
||||
let commit2_target = RefTarget::normal(jj_id(&commit2));
|
||||
let expected_main_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit2))),
|
||||
local_target: RefTarget::normal(jj_id(&commit2)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => commit1_target.clone(),
|
||||
"origin".to_string() => commit1_target.clone().unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -263,16 +263,10 @@ fn test_import_refs_reimport() {
|
||||
assert!(view.tags().is_empty());
|
||||
|
||||
assert_eq!(view.git_refs().len(), 3);
|
||||
assert_eq!(view.get_git_ref("refs/heads/main"), Some(commit2_target));
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/remotes/origin/main"),
|
||||
Some(commit1_target)
|
||||
);
|
||||
let commit5_target = RefTarget::Normal(jj_id(&commit5));
|
||||
assert_eq!(
|
||||
view.get_git_ref("refs/heads/feature2"),
|
||||
Some(commit5_target)
|
||||
);
|
||||
assert_eq!(view.get_git_ref("refs/heads/main"), commit2_target);
|
||||
assert_eq!(view.get_git_ref("refs/remotes/origin/main"), commit1_target);
|
||||
let commit5_target = RefTarget::normal(jj_id(&commit5));
|
||||
assert_eq!(view.get_git_ref("refs/heads/feature2"), commit5_target);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -443,18 +437,18 @@ fn test_import_refs_reimport_with_deleted_remote_ref() {
|
||||
Some(&BranchTarget {
|
||||
// Even though the git repo does not have a local branch for `feature-remote-only`, jj
|
||||
// creates one. This follows the model explained in docs/branches.md.
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_remote_only))),
|
||||
local_target: RefTarget::normal(jj_id(&commit_remote_only)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&commit_remote_only))
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&commit_remote_only)).unwrap(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
view.branches().get("feature-remote-and-local"),
|
||||
Some(&BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_remote_and_local))),
|
||||
local_target: RefTarget::normal(jj_id(&commit_remote_and_local)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&commit_remote_and_local))
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&commit_remote_and_local)).unwrap(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -532,18 +526,18 @@ fn test_import_refs_reimport_with_moved_remote_ref() {
|
||||
Some(&BranchTarget {
|
||||
// Even though the git repo does not have a local branch for `feature-remote-only`, jj
|
||||
// creates one. This follows the model explained in docs/branches.md.
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_remote_only))),
|
||||
local_target: RefTarget::normal(jj_id(&commit_remote_only)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&commit_remote_only))
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&commit_remote_only)).unwrap(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
view.branches().get("feature-remote-and-local"),
|
||||
Some(&BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_remote_and_local))),
|
||||
local_target: RefTarget::normal(jj_id(&commit_remote_and_local)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&commit_remote_and_local))
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&commit_remote_and_local)).unwrap(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -576,18 +570,18 @@ fn test_import_refs_reimport_with_moved_remote_ref() {
|
||||
assert_eq!(
|
||||
view.branches().get("feature-remote-only"),
|
||||
Some(&BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&new_commit_remote_only))),
|
||||
local_target: RefTarget::normal(jj_id(&new_commit_remote_only)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&new_commit_remote_only))
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&new_commit_remote_only)).unwrap(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
view.branches().get("feature-remote-and-local"),
|
||||
Some(&BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&new_commit_remote_and_local))),
|
||||
local_target: RefTarget::normal(jj_id(&new_commit_remote_and_local)),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&new_commit_remote_and_local))
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&new_commit_remote_and_local)).unwrap(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -712,37 +706,37 @@ fn test_import_some_refs() {
|
||||
// Check that branches feature[1-4] have been locally imported and are known to
|
||||
// be present on origin as well.
|
||||
assert_eq!(view.branches().len(), 4);
|
||||
let commit_feat1_target = RefTarget::Normal(jj_id(&commit_feat1));
|
||||
let commit_feat2_target = RefTarget::Normal(jj_id(&commit_feat2));
|
||||
let commit_feat3_target = RefTarget::Normal(jj_id(&commit_feat3));
|
||||
let commit_feat4_target = RefTarget::Normal(jj_id(&commit_feat4));
|
||||
let commit_feat1_target = RefTarget::normal(jj_id(&commit_feat1));
|
||||
let commit_feat2_target = RefTarget::normal(jj_id(&commit_feat2));
|
||||
let commit_feat3_target = RefTarget::normal(jj_id(&commit_feat3));
|
||||
let commit_feat4_target = RefTarget::normal(jj_id(&commit_feat4));
|
||||
let expected_feature1_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_feat1))),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat1_target },
|
||||
local_target: RefTarget::normal(jj_id(&commit_feat1)),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat1_target.unwrap() },
|
||||
};
|
||||
assert_eq!(
|
||||
view.branches().get("feature1"),
|
||||
Some(expected_feature1_branch).as_ref()
|
||||
);
|
||||
let expected_feature2_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_feat2))),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat2_target },
|
||||
local_target: RefTarget::normal(jj_id(&commit_feat2)),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat2_target.unwrap() },
|
||||
};
|
||||
assert_eq!(
|
||||
view.branches().get("feature2"),
|
||||
Some(expected_feature2_branch).as_ref()
|
||||
);
|
||||
let expected_feature3_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_feat3))),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat3_target },
|
||||
local_target: RefTarget::normal(jj_id(&commit_feat3)),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat3_target.unwrap() },
|
||||
};
|
||||
assert_eq!(
|
||||
view.branches().get("feature3"),
|
||||
Some(expected_feature3_branch).as_ref()
|
||||
);
|
||||
let expected_feature4_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(jj_id(&commit_feat4))),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat4_target },
|
||||
local_target: RefTarget::normal(jj_id(&commit_feat4)),
|
||||
remote_targets: btreemap! { "origin".to_string() => commit_feat4_target.unwrap() },
|
||||
};
|
||||
assert_eq!(
|
||||
view.branches().get("feature4"),
|
||||
@ -926,7 +920,7 @@ fn test_import_refs_detached_head() {
|
||||
assert_eq!(repo.view().git_refs().len(), 0);
|
||||
assert_eq!(
|
||||
repo.view().git_head(),
|
||||
Some(&RefTarget::Normal(jj_id(&commit1)))
|
||||
RefTarget::normal(jj_id(&commit1)).as_ref()
|
||||
);
|
||||
}
|
||||
|
||||
@ -950,7 +944,7 @@ fn test_export_refs_no_detach() {
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(jj_id(&commit1)))
|
||||
RefTarget::normal(jj_id(&commit1))
|
||||
);
|
||||
assert_eq!(git_repo.head().unwrap().name(), Some("refs/heads/main"));
|
||||
assert_eq!(
|
||||
@ -983,11 +977,11 @@ fn test_export_refs_branch_changed() {
|
||||
.set_parents(vec![jj_id(&commit)])
|
||||
.write()
|
||||
.unwrap();
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(new_commit.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(new_commit.id().clone()));
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(new_commit.id().clone()))
|
||||
RefTarget::normal(new_commit.id().clone())
|
||||
);
|
||||
assert_eq!(
|
||||
git_repo
|
||||
@ -1022,11 +1016,11 @@ fn test_export_refs_current_branch_changed() {
|
||||
.set_parents(vec![jj_id(&commit1)])
|
||||
.write()
|
||||
.unwrap();
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(new_commit.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(new_commit.id().clone()));
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(new_commit.id().clone()))
|
||||
RefTarget::normal(new_commit.id().clone())
|
||||
);
|
||||
assert_eq!(
|
||||
git_repo
|
||||
@ -1056,11 +1050,11 @@ fn test_export_refs_unborn_git_branch() {
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
|
||||
let new_commit = write_random_commit(mut_repo, &test_data.settings);
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(new_commit.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(new_commit.id().clone()));
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(new_commit.id().clone()))
|
||||
RefTarget::normal(new_commit.id().clone())
|
||||
);
|
||||
assert_eq!(
|
||||
git_repo
|
||||
@ -1100,17 +1094,17 @@ fn test_export_import_sequence() {
|
||||
git::import_refs(mut_repo, &git_repo, &git_settings).unwrap();
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(commit_a.id().clone()))
|
||||
RefTarget::normal(commit_a.id().clone())
|
||||
);
|
||||
|
||||
// Modify the branch in jj to point to B
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(commit_b.id().clone()));
|
||||
|
||||
// Export the branch to git
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(commit_b.id().clone()))
|
||||
RefTarget::normal(commit_b.id().clone())
|
||||
);
|
||||
|
||||
// Modify the branch in git to point to C
|
||||
@ -1122,11 +1116,11 @@ fn test_export_import_sequence() {
|
||||
git::import_refs(mut_repo, &git_repo, &git_settings).unwrap();
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(commit_c.id().clone()))
|
||||
RefTarget::normal(commit_c.id().clone())
|
||||
);
|
||||
assert_eq!(
|
||||
mut_repo.view().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_c.id().clone()))
|
||||
RefTarget::normal(commit_c.id().clone())
|
||||
);
|
||||
}
|
||||
|
||||
@ -1151,7 +1145,7 @@ fn test_import_export_no_auto_local_branch() {
|
||||
let expected_branch = BranchTarget {
|
||||
local_target: None,
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(jj_id(&git_commit))
|
||||
"origin".to_string() => RefTarget::normal(jj_id(&git_commit)).unwrap(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -1160,7 +1154,7 @@ fn test_import_export_no_auto_local_branch() {
|
||||
);
|
||||
assert_eq!(
|
||||
mut_repo.get_git_ref("refs/remotes/origin/main"),
|
||||
Some(RefTarget::Normal(jj_id(&git_commit)))
|
||||
RefTarget::normal(jj_id(&git_commit))
|
||||
);
|
||||
|
||||
// Export the branch to git
|
||||
@ -1180,13 +1174,13 @@ fn test_export_conflicts() {
|
||||
let commit_a = write_random_commit(mut_repo, &test_data.settings);
|
||||
let commit_b = write_random_commit(mut_repo, &test_data.settings);
|
||||
let commit_c = write_random_commit(mut_repo, &test_data.settings);
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(commit_a.id().clone())));
|
||||
mut_repo.set_local_branch_target("feature", Some(RefTarget::Normal(commit_a.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(commit_a.id().clone()));
|
||||
mut_repo.set_local_branch_target("feature", RefTarget::normal(commit_a.id().clone()));
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
|
||||
// Create a conflict and export. It should not be exported, but other changes
|
||||
// should be.
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(commit_b.id().clone()));
|
||||
mut_repo.set_local_branch_target(
|
||||
"feature",
|
||||
Some(RefTarget::Conflict {
|
||||
@ -1223,7 +1217,7 @@ fn test_export_partial_failure() {
|
||||
.start_transaction(&test_data.settings, "test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let commit_a = write_random_commit(mut_repo, &test_data.settings);
|
||||
let target = Some(RefTarget::Normal(commit_a.id().clone()));
|
||||
let target = RefTarget::normal(commit_a.id().clone());
|
||||
// Empty string is disallowed by Git
|
||||
mut_repo.set_local_branch_target("", target.clone());
|
||||
// Branch named HEAD is disallowed by Git CLI
|
||||
@ -1313,7 +1307,7 @@ fn test_export_reexport_transitions() {
|
||||
for branch in [
|
||||
"AAB", "AAX", "ABA", "ABB", "ABC", "ABX", "AXA", "AXB", "AXX",
|
||||
] {
|
||||
mut_repo.set_local_branch_target(branch, Some(RefTarget::Normal(commit_a.id().clone())));
|
||||
mut_repo.set_local_branch_target(branch, RefTarget::normal(commit_a.id().clone()));
|
||||
}
|
||||
assert_eq!(git::export_refs(mut_repo, &git_repo), Ok(vec![]));
|
||||
|
||||
@ -1322,10 +1316,10 @@ fn test_export_reexport_transitions() {
|
||||
mut_repo.set_local_branch_target(branch, None);
|
||||
}
|
||||
for branch in ["XAA", "XAB", "XAX"] {
|
||||
mut_repo.set_local_branch_target(branch, Some(RefTarget::Normal(commit_a.id().clone())));
|
||||
mut_repo.set_local_branch_target(branch, RefTarget::normal(commit_a.id().clone()));
|
||||
}
|
||||
for branch in ["ABA", "ABB", "ABC", "ABX"] {
|
||||
mut_repo.set_local_branch_target(branch, Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
mut_repo.set_local_branch_target(branch, RefTarget::normal(commit_b.id().clone()));
|
||||
}
|
||||
|
||||
// Make changes on the git side
|
||||
@ -1401,15 +1395,15 @@ fn test_export_reexport_transitions() {
|
||||
assert_eq!(
|
||||
*mut_repo.view().git_refs(),
|
||||
btreemap! {
|
||||
"refs/heads/AAX".to_string() => RefTarget::Normal(commit_a.id().clone()),
|
||||
"refs/heads/AAB".to_string() => RefTarget::Normal(commit_a.id().clone()),
|
||||
"refs/heads/ABA".to_string() => RefTarget::Normal(commit_b.id().clone()),
|
||||
"refs/heads/ABB".to_string() => RefTarget::Normal(commit_b.id().clone()),
|
||||
"refs/heads/ABC".to_string() => RefTarget::Normal(commit_a.id().clone()),
|
||||
"refs/heads/ABX".to_string() => RefTarget::Normal(commit_a.id().clone()),
|
||||
"refs/heads/AXB".to_string() => RefTarget::Normal(commit_a.id().clone()),
|
||||
"refs/heads/XAA".to_string() => RefTarget::Normal(commit_a.id().clone()),
|
||||
"refs/heads/XAX".to_string() => RefTarget::Normal(commit_a.id().clone()),
|
||||
"refs/heads/AAX".to_string() => RefTarget::normal(commit_a.id().clone()).unwrap(),
|
||||
"refs/heads/AAB".to_string() => RefTarget::normal(commit_a.id().clone()).unwrap(),
|
||||
"refs/heads/ABA".to_string() => RefTarget::normal(commit_b.id().clone()).unwrap(),
|
||||
"refs/heads/ABB".to_string() => RefTarget::normal(commit_b.id().clone()).unwrap(),
|
||||
"refs/heads/ABC".to_string() => RefTarget::normal(commit_a.id().clone()).unwrap(),
|
||||
"refs/heads/ABX".to_string() => RefTarget::normal(commit_a.id().clone()).unwrap(),
|
||||
"refs/heads/AXB".to_string() => RefTarget::normal(commit_a.id().clone()).unwrap(),
|
||||
"refs/heads/XAA".to_string() => RefTarget::normal(commit_a.id().clone()).unwrap(),
|
||||
"refs/heads/XAX".to_string() => RefTarget::normal(commit_a.id().clone()).unwrap(),
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -1490,19 +1484,19 @@ fn test_fetch_initial_commit() {
|
||||
// The initial commit is visible after git::fetch().
|
||||
let view = repo.view();
|
||||
assert!(view.heads().contains(&jj_id(&initial_git_commit)));
|
||||
let initial_commit_target = RefTarget::Normal(jj_id(&initial_git_commit));
|
||||
let initial_commit_target = RefTarget::normal(jj_id(&initial_git_commit));
|
||||
assert_eq!(
|
||||
*view.git_refs(),
|
||||
btreemap! {
|
||||
"refs/remotes/origin/main".to_string() => initial_commit_target.clone(),
|
||||
"refs/remotes/origin/main".to_string() => initial_commit_target.clone().unwrap(),
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
*view.branches(),
|
||||
btreemap! {
|
||||
"main".to_string() => BranchTarget {
|
||||
local_target: Some(initial_commit_target.clone()),
|
||||
remote_targets: btreemap! {"origin".to_string() => initial_commit_target}
|
||||
local_target: initial_commit_target.clone(),
|
||||
remote_targets: btreemap! {"origin".to_string() => initial_commit_target.unwrap()}
|
||||
},
|
||||
}
|
||||
);
|
||||
@ -1553,19 +1547,19 @@ fn test_fetch_success() {
|
||||
// The new commit is visible after we fetch again
|
||||
let view = repo.view();
|
||||
assert!(view.heads().contains(&jj_id(&new_git_commit)));
|
||||
let new_commit_target = RefTarget::Normal(jj_id(&new_git_commit));
|
||||
let new_commit_target = RefTarget::normal(jj_id(&new_git_commit));
|
||||
assert_eq!(
|
||||
*view.git_refs(),
|
||||
btreemap! {
|
||||
"refs/remotes/origin/main".to_string() => new_commit_target.clone(),
|
||||
"refs/remotes/origin/main".to_string() => new_commit_target.clone().unwrap(),
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
*view.branches(),
|
||||
btreemap! {
|
||||
"main".to_string() => BranchTarget {
|
||||
local_target: Some(new_commit_target.clone()),
|
||||
remote_targets: btreemap! {"origin".to_string() => new_commit_target}
|
||||
local_target: new_commit_target.clone(),
|
||||
remote_targets: btreemap! {"origin".to_string() => new_commit_target.unwrap()}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
@ -170,7 +170,7 @@ fn test_checkout_previous_empty_with_local_branch(use_git: bool) {
|
||||
)
|
||||
.write()
|
||||
.unwrap();
|
||||
mut_repo.set_local_branch_target("b", Some(RefTarget::Normal(old_wc_commit.id().clone())));
|
||||
mut_repo.set_local_branch_target("b", RefTarget::normal(old_wc_commit.id().clone()));
|
||||
let ws_id = WorkspaceId::default();
|
||||
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
|
||||
let repo = tx.commit();
|
||||
@ -469,12 +469,8 @@ fn test_has_changed(use_git: bool) {
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(commit1.id().clone())));
|
||||
mut_repo.set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit1.id().clone())),
|
||||
);
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(commit1.id().clone()));
|
||||
mut_repo.set_remote_branch_target("main", "origin", RefTarget::normal(commit1.id().clone()));
|
||||
let repo = tx.commit();
|
||||
// Test the setup
|
||||
assert_eq!(repo.view().heads(), &hashset! {commit1.id().clone()});
|
||||
@ -488,12 +484,8 @@ fn test_has_changed(use_git: bool) {
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(commit1.id().clone())));
|
||||
mut_repo.set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit1.id().clone())),
|
||||
);
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(commit1.id().clone()));
|
||||
mut_repo.set_remote_branch_target("main", "origin", RefTarget::normal(commit1.id().clone()));
|
||||
assert!(!mut_repo.has_changes());
|
||||
|
||||
mut_repo.remove_public_head(commit2.id());
|
||||
@ -524,22 +516,14 @@ fn test_has_changed(use_git: bool) {
|
||||
mut_repo.set_wc_commit(ws_id, commit1.id().clone()).unwrap();
|
||||
assert!(!mut_repo.has_changes());
|
||||
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(commit2.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(commit2.id().clone()));
|
||||
assert!(mut_repo.has_changes());
|
||||
mut_repo.set_local_branch_target("main", Some(RefTarget::Normal(commit1.id().clone())));
|
||||
mut_repo.set_local_branch_target("main", RefTarget::normal(commit1.id().clone()));
|
||||
assert!(!mut_repo.has_changes());
|
||||
|
||||
mut_repo.set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
);
|
||||
mut_repo.set_remote_branch_target("main", "origin", RefTarget::normal(commit2.id().clone()));
|
||||
assert!(mut_repo.has_changes());
|
||||
mut_repo.set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit1.id().clone())),
|
||||
);
|
||||
mut_repo.set_remote_branch_target("main", "origin", RefTarget::normal(commit1.id().clone()));
|
||||
assert!(!mut_repo.has_changes());
|
||||
}
|
||||
|
||||
@ -626,7 +610,7 @@ fn test_rename_remote(use_git: bool) {
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let commit = write_random_commit(mut_repo, &settings);
|
||||
let target = Some(RefTarget::Normal(commit.id().clone()));
|
||||
let target = RefTarget::normal(commit.id().clone());
|
||||
mut_repo.set_remote_branch_target("main", "origin", target.clone());
|
||||
mut_repo.rename_remote("origin", "upstream");
|
||||
assert_eq!(mut_repo.get_remote_branch("main", "upstream"), target);
|
||||
|
@ -42,91 +42,91 @@ fn test_merge_ref_targets() {
|
||||
let commit7 = graph_builder.commit_with_parents(&[&commit5]);
|
||||
let repo = tx.commit();
|
||||
|
||||
let target1 = RefTarget::Normal(commit1.id().clone());
|
||||
let target2 = RefTarget::Normal(commit2.id().clone());
|
||||
let target3 = RefTarget::Normal(commit3.id().clone());
|
||||
let target4 = RefTarget::Normal(commit4.id().clone());
|
||||
let target5 = RefTarget::Normal(commit5.id().clone());
|
||||
let target6 = RefTarget::Normal(commit6.id().clone());
|
||||
let _target7 = RefTarget::Normal(commit7.id().clone());
|
||||
let target1 = RefTarget::normal(commit1.id().clone());
|
||||
let target2 = RefTarget::normal(commit2.id().clone());
|
||||
let target3 = RefTarget::normal(commit3.id().clone());
|
||||
let target4 = RefTarget::normal(commit4.id().clone());
|
||||
let target5 = RefTarget::normal(commit5.id().clone());
|
||||
let target6 = RefTarget::normal(commit6.id().clone());
|
||||
let _target7 = RefTarget::normal(commit7.id().clone());
|
||||
|
||||
let index = repo.index();
|
||||
|
||||
// Left moved forward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target1), Some(&target1)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target3.as_ref(), target1.as_ref(), target1.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Right moved forward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target1), Some(&target1), Some(&target3)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target1.as_ref(), target1.as_ref(), target3.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Left moved backward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target1), Some(&target3), Some(&target3)),
|
||||
Some(target1.clone())
|
||||
merge_ref_targets(index, target1.as_ref(), target3.as_ref(), target3.as_ref()),
|
||||
target1
|
||||
);
|
||||
|
||||
// Right moved backward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target3), Some(&target1)),
|
||||
Some(target1.clone())
|
||||
merge_ref_targets(index, target3.as_ref(), target3.as_ref(), target1.as_ref()),
|
||||
target1
|
||||
);
|
||||
|
||||
// Left moved sideways
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target4), Some(&target3), Some(&target3)),
|
||||
Some(target4.clone())
|
||||
merge_ref_targets(index, target4.as_ref(), target3.as_ref(), target3.as_ref()),
|
||||
target4
|
||||
);
|
||||
|
||||
// Right moved sideways
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target3), Some(&target4)),
|
||||
Some(target4.clone())
|
||||
merge_ref_targets(index, target3.as_ref(), target3.as_ref(), target4.as_ref()),
|
||||
target4
|
||||
);
|
||||
|
||||
// Both added same target
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), None, Some(&target3)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target3.as_ref(), None, target3.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Left added target, right added descendant target
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target2), None, Some(&target3)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target2.as_ref(), None, target3.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Right added target, left added descendant target
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), None, Some(&target2)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target3.as_ref(), None, target2.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Both moved forward to same target
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target1), Some(&target3)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target3.as_ref(), target1.as_ref(), target3.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Both moved forward, left moved further
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target1), Some(&target2)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target3.as_ref(), target1.as_ref(), target2.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Both moved forward, right moved further
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target2), Some(&target1), Some(&target3)),
|
||||
Some(target3.clone())
|
||||
merge_ref_targets(index, target2.as_ref(), target1.as_ref(), target3.as_ref()),
|
||||
target3
|
||||
);
|
||||
|
||||
// Left and right moved forward to divergent targets
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target1), Some(&target4)),
|
||||
merge_ref_targets(index, target3.as_ref(), target1.as_ref(), target4.as_ref()),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit1.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
@ -135,7 +135,7 @@ fn test_merge_ref_targets() {
|
||||
|
||||
// Left moved back, right moved forward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target1), Some(&target2), Some(&target3)),
|
||||
merge_ref_targets(index, target1.as_ref(), target2.as_ref(), target3.as_ref()),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit1.id().clone(), commit3.id().clone()]
|
||||
@ -144,7 +144,7 @@ fn test_merge_ref_targets() {
|
||||
|
||||
// Right moved back, left moved forward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target2), Some(&target1)),
|
||||
merge_ref_targets(index, target3.as_ref(), target2.as_ref(), target1.as_ref()),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit1.id().clone()]
|
||||
@ -153,19 +153,19 @@ fn test_merge_ref_targets() {
|
||||
|
||||
// Left removed
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, None, Some(&target3), Some(&target3)),
|
||||
merge_ref_targets(index, None, target3.as_ref(), target3.as_ref()),
|
||||
None
|
||||
);
|
||||
|
||||
// Right removed
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target3), None),
|
||||
merge_ref_targets(index, target3.as_ref(), target3.as_ref(), None),
|
||||
None
|
||||
);
|
||||
|
||||
// Left removed, right moved forward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, None, Some(&target1), Some(&target3)),
|
||||
merge_ref_targets(index, None, target1.as_ref(), target3.as_ref()),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit1.id().clone()],
|
||||
adds: vec![commit3.id().clone()]
|
||||
@ -174,7 +174,7 @@ fn test_merge_ref_targets() {
|
||||
|
||||
// Right removed, left moved forward
|
||||
assert_eq!(
|
||||
merge_ref_targets(index, Some(&target3), Some(&target1), None),
|
||||
merge_ref_targets(index, target3.as_ref(), target1.as_ref(), None),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit1.id().clone()],
|
||||
adds: vec![commit3.id().clone()]
|
||||
@ -189,8 +189,8 @@ fn test_merge_ref_targets() {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
}),
|
||||
Some(&target1),
|
||||
Some(&target3)
|
||||
target1.as_ref(),
|
||||
target3.as_ref()
|
||||
),
|
||||
// TODO: "removes" should have commit 2, just like it does in the next test case
|
||||
Some(RefTarget::Conflict {
|
||||
@ -203,8 +203,8 @@ fn test_merge_ref_targets() {
|
||||
assert_eq!(
|
||||
merge_ref_targets(
|
||||
index,
|
||||
Some(&target3),
|
||||
Some(&target1),
|
||||
target3.as_ref(),
|
||||
target1.as_ref(),
|
||||
Some(&RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
@ -231,8 +231,8 @@ fn test_merge_ref_targets() {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
}),
|
||||
Some(&target3),
|
||||
Some(&target5)
|
||||
target3.as_ref(),
|
||||
target5.as_ref()
|
||||
),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
@ -251,8 +251,8 @@ fn test_merge_ref_targets() {
|
||||
assert_eq!(
|
||||
merge_ref_targets(
|
||||
index,
|
||||
Some(&target5),
|
||||
Some(&target3),
|
||||
target5.as_ref(),
|
||||
target3.as_ref(),
|
||||
Some(&RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
@ -280,8 +280,8 @@ fn test_merge_ref_targets() {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
}),
|
||||
Some(&target3),
|
||||
Some(&target1)
|
||||
target3.as_ref(),
|
||||
target1.as_ref()
|
||||
),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
@ -301,8 +301,8 @@ fn test_merge_ref_targets() {
|
||||
assert_eq!(
|
||||
merge_ref_targets(
|
||||
index,
|
||||
Some(&target1),
|
||||
Some(&target3),
|
||||
target1.as_ref(),
|
||||
target3.as_ref(),
|
||||
Some(&RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
@ -322,24 +322,24 @@ fn test_merge_ref_targets() {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
}),
|
||||
Some(&target3),
|
||||
Some(&target2)
|
||||
target3.as_ref(),
|
||||
target2.as_ref()
|
||||
),
|
||||
Some(target4.clone())
|
||||
target4
|
||||
);
|
||||
|
||||
// Existing conflict on right, left undoes one side of conflict
|
||||
assert_eq!(
|
||||
merge_ref_targets(
|
||||
index,
|
||||
Some(&target2),
|
||||
Some(&target3),
|
||||
target2.as_ref(),
|
||||
target3.as_ref(),
|
||||
Some(&RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
})
|
||||
),
|
||||
Some(target4)
|
||||
target4
|
||||
);
|
||||
|
||||
// Existing conflict on left, right makes unrelated update
|
||||
@ -350,8 +350,8 @@ fn test_merge_ref_targets() {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
}),
|
||||
Some(&target5),
|
||||
Some(&target6)
|
||||
target5.as_ref(),
|
||||
target6.as_ref()
|
||||
),
|
||||
Some(RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone(), commit5.id().clone()],
|
||||
@ -367,8 +367,8 @@ fn test_merge_ref_targets() {
|
||||
assert_eq!(
|
||||
merge_ref_targets(
|
||||
index,
|
||||
Some(&target6),
|
||||
Some(&target5),
|
||||
target6.as_ref(),
|
||||
target5.as_ref(),
|
||||
Some(&RefTarget::Conflict {
|
||||
removes: vec![commit2.id().clone()],
|
||||
adds: vec![commit3.id().clone(), commit4.id().clone()]
|
||||
|
@ -425,20 +425,13 @@ fn test_resolve_symbol_branches() {
|
||||
let commit4 = write_random_commit(mut_repo, &settings);
|
||||
let commit5 = write_random_commit(mut_repo, &settings);
|
||||
|
||||
mut_repo.set_local_branch_target("local", Some(RefTarget::Normal(commit1.id().clone())));
|
||||
mut_repo.set_remote_branch_target(
|
||||
"remote",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
);
|
||||
mut_repo.set_local_branch_target(
|
||||
"local-remote",
|
||||
Some(RefTarget::Normal(commit3.id().clone())),
|
||||
);
|
||||
mut_repo.set_local_branch_target("local", RefTarget::normal(commit1.id().clone()));
|
||||
mut_repo.set_remote_branch_target("remote", "origin", RefTarget::normal(commit2.id().clone()));
|
||||
mut_repo.set_local_branch_target("local-remote", RefTarget::normal(commit3.id().clone()));
|
||||
mut_repo.set_remote_branch_target(
|
||||
"local-remote",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit4.id().clone())),
|
||||
RefTarget::normal(commit4.id().clone()),
|
||||
);
|
||||
mut_repo.set_remote_branch_target(
|
||||
"local-remote",
|
||||
@ -649,7 +642,7 @@ fn test_resolve_symbol_git_head() {
|
||||
"###);
|
||||
|
||||
// With HEAD@git
|
||||
mut_repo.set_git_head_target(Some(RefTarget::Normal(commit1.id().clone())));
|
||||
mut_repo.set_git_head_target(RefTarget::normal(commit1.id().clone()));
|
||||
insta::assert_debug_snapshot!(
|
||||
resolve_symbol(mut_repo, "HEAD", None).unwrap_err(), @r###"
|
||||
NoSuchRevision {
|
||||
@ -682,11 +675,11 @@ fn test_resolve_symbol_git_refs() {
|
||||
let commit5 = write_random_commit(mut_repo, &settings);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/branch1",
|
||||
Some(RefTarget::Normal(commit1.id().clone())),
|
||||
RefTarget::normal(commit1.id().clone()),
|
||||
);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/branch2",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
RefTarget::normal(commit2.id().clone()),
|
||||
);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/conflicted",
|
||||
@ -695,13 +688,10 @@ fn test_resolve_symbol_git_refs() {
|
||||
adds: vec![commit1.id().clone(), commit3.id().clone()],
|
||||
}),
|
||||
);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/tags/tag1",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
);
|
||||
mut_repo.set_git_ref_target("refs/tags/tag1", RefTarget::normal(commit2.id().clone()));
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/tags/remotes/origin/branch1",
|
||||
Some(RefTarget::Normal(commit3.id().clone())),
|
||||
RefTarget::normal(commit3.id().clone()),
|
||||
);
|
||||
|
||||
// Nonexistent ref
|
||||
@ -712,20 +702,14 @@ fn test_resolve_symbol_git_refs() {
|
||||
);
|
||||
|
||||
// Full ref
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/branch",
|
||||
Some(RefTarget::Normal(commit4.id().clone())),
|
||||
);
|
||||
mut_repo.set_git_ref_target("refs/heads/branch", RefTarget::normal(commit4.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_symbol(mut_repo, "refs/heads/branch", None).unwrap(),
|
||||
vec![commit4.id().clone()]
|
||||
);
|
||||
|
||||
// Qualified with only heads/
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/branch",
|
||||
Some(RefTarget::Normal(commit5.id().clone())),
|
||||
);
|
||||
mut_repo.set_git_ref_target("refs/heads/branch", RefTarget::normal(commit5.id().clone()));
|
||||
// branch alone is not recognized
|
||||
insta::assert_debug_snapshot!(
|
||||
resolve_symbol(mut_repo, "branch", None).unwrap_err(), @r###"
|
||||
@ -738,10 +722,7 @@ fn test_resolve_symbol_git_refs() {
|
||||
],
|
||||
}
|
||||
"###);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/tags/branch",
|
||||
Some(RefTarget::Normal(commit4.id().clone())),
|
||||
);
|
||||
mut_repo.set_git_ref_target("refs/tags/branch", RefTarget::normal(commit4.id().clone()));
|
||||
// The *tag* branch is recognized
|
||||
assert_eq!(
|
||||
resolve_symbol(mut_repo, "branch", None).unwrap(),
|
||||
@ -754,10 +735,7 @@ fn test_resolve_symbol_git_refs() {
|
||||
);
|
||||
|
||||
// Unqualified tag name
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/tags/tag",
|
||||
Some(RefTarget::Normal(commit4.id().clone())),
|
||||
);
|
||||
mut_repo.set_git_ref_target("refs/tags/tag", RefTarget::normal(commit4.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_symbol(mut_repo, "tag", None).unwrap(),
|
||||
vec![commit4.id().clone()]
|
||||
@ -766,7 +744,7 @@ fn test_resolve_symbol_git_refs() {
|
||||
// Unqualified remote-tracking branch name
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/remotes/origin/remote-branch",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
RefTarget::normal(commit2.id().clone()),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_symbol(mut_repo, "origin/remote-branch", None).unwrap(),
|
||||
@ -778,8 +756,8 @@ fn test_resolve_symbol_git_refs() {
|
||||
mut_repo
|
||||
.set_wc_commit(ws_id.clone(), commit1.id().clone())
|
||||
.unwrap();
|
||||
mut_repo.set_git_ref_target("@", Some(RefTarget::Normal(commit2.id().clone())));
|
||||
mut_repo.set_git_ref_target("root", Some(RefTarget::Normal(commit3.id().clone())));
|
||||
mut_repo.set_git_ref_target("@", RefTarget::normal(commit2.id().clone()));
|
||||
mut_repo.set_git_ref_target("root", RefTarget::normal(commit3.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_symbol(mut_repo, "@", Some(&ws_id)).unwrap(),
|
||||
vec![mut_repo.view().get_wc_commit_id(&ws_id).unwrap().clone()]
|
||||
@ -1617,22 +1595,16 @@ fn test_evaluate_expression_git_refs(use_git: bool) {
|
||||
// Can get a mix of git refs
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/branch1",
|
||||
Some(RefTarget::Normal(commit1.id().clone())),
|
||||
);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/tags/tag1",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
RefTarget::normal(commit1.id().clone()),
|
||||
);
|
||||
mut_repo.set_git_ref_target("refs/tags/tag1", RefTarget::normal(commit2.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo, "git_refs()"),
|
||||
vec![commit2.id().clone(), commit1.id().clone()]
|
||||
);
|
||||
// Two refs pointing to the same commit does not result in a duplicate in the
|
||||
// revset
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/tags/tag2",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
);
|
||||
mut_repo.set_git_ref_target("refs/tags/tag2", RefTarget::normal(commit2.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo, "git_refs()"),
|
||||
vec![commit2.id().clone(), commit1.id().clone()]
|
||||
@ -1677,7 +1649,7 @@ fn test_evaluate_expression_git_head(use_git: bool) {
|
||||
|
||||
// Can get git head when it's not set
|
||||
assert_eq!(resolve_commit_ids(mut_repo, "git_head()"), vec![]);
|
||||
mut_repo.set_git_head_target(Some(RefTarget::Normal(commit1.id().clone())));
|
||||
mut_repo.set_git_head_target(RefTarget::normal(commit1.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo, "git_head()"),
|
||||
vec![commit1.id().clone()]
|
||||
@ -1702,8 +1674,8 @@ fn test_evaluate_expression_branches(use_git: bool) {
|
||||
// Can get branches when there are none
|
||||
assert_eq!(resolve_commit_ids(mut_repo, "branches()"), vec![]);
|
||||
// Can get a few branches
|
||||
mut_repo.set_local_branch_target("branch1", Some(RefTarget::Normal(commit1.id().clone())));
|
||||
mut_repo.set_local_branch_target("branch2", Some(RefTarget::Normal(commit2.id().clone())));
|
||||
mut_repo.set_local_branch_target("branch1", RefTarget::normal(commit1.id().clone()));
|
||||
mut_repo.set_local_branch_target("branch2", RefTarget::normal(commit2.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo, "branches()"),
|
||||
vec![commit2.id().clone(), commit1.id().clone()]
|
||||
@ -1721,7 +1693,7 @@ fn test_evaluate_expression_branches(use_git: bool) {
|
||||
assert_eq!(resolve_commit_ids(mut_repo, "branches(branch3)"), vec![]);
|
||||
// Two branches pointing to the same commit does not result in a duplicate in
|
||||
// the revset
|
||||
mut_repo.set_local_branch_target("branch3", Some(RefTarget::Normal(commit2.id().clone())));
|
||||
mut_repo.set_local_branch_target("branch3", RefTarget::normal(commit2.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo, "branches()"),
|
||||
vec![commit2.id().clone(), commit1.id().clone()]
|
||||
@ -1770,15 +1742,11 @@ fn test_evaluate_expression_remote_branches(use_git: bool) {
|
||||
// Can get branches when there are none
|
||||
assert_eq!(resolve_commit_ids(mut_repo, "remote_branches()"), vec![]);
|
||||
// Can get a few branches
|
||||
mut_repo.set_remote_branch_target(
|
||||
"branch1",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit1.id().clone())),
|
||||
);
|
||||
mut_repo.set_remote_branch_target("branch1", "origin", RefTarget::normal(commit1.id().clone()));
|
||||
mut_repo.set_remote_branch_target(
|
||||
"branch2",
|
||||
"private",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
RefTarget::normal(commit2.id().clone()),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo, "remote_branches()"),
|
||||
@ -1826,11 +1794,7 @@ fn test_evaluate_expression_remote_branches(use_git: bool) {
|
||||
);
|
||||
// Two branches pointing to the same commit does not result in a duplicate in
|
||||
// the revset
|
||||
mut_repo.set_remote_branch_target(
|
||||
"branch3",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit2.id().clone())),
|
||||
);
|
||||
mut_repo.set_remote_branch_target("branch3", "origin", RefTarget::normal(commit2.id().clone()));
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo, "remote_branches()"),
|
||||
vec![commit2.id().clone(), commit1.id().clone()]
|
||||
@ -2766,7 +2730,7 @@ fn test_no_such_revision_suggestion() {
|
||||
mut_repo.set_branch(
|
||||
branch_name.to_string(),
|
||||
BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(commit.id().clone())),
|
||||
local_target: RefTarget::normal(commit.id().clone()),
|
||||
remote_targets: Default::default(),
|
||||
},
|
||||
);
|
||||
|
@ -935,7 +935,7 @@ fn test_rebase_descendants_basic_branch_update() {
|
||||
let commit_a = graph_builder.initial_commit();
|
||||
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target("main", Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
.set_local_branch_target("main", RefTarget::normal(commit_b.id().clone()));
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
@ -947,7 +947,7 @@ fn test_rebase_descendants_basic_branch_update() {
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_b2.id().clone()))
|
||||
RefTarget::normal(commit_b2.id().clone())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -978,7 +978,7 @@ fn test_rebase_descendants_branch_move_two_steps() {
|
||||
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
|
||||
let commit_c = graph_builder.commit_with_parents(&[&commit_b]);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target("main", Some(RefTarget::Normal(commit_c.id().clone())));
|
||||
.set_local_branch_target("main", RefTarget::normal(commit_c.id().clone()));
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
@ -1001,7 +1001,7 @@ fn test_rebase_descendants_branch_move_two_steps() {
|
||||
assert_eq!(commit_c3.parent_ids(), vec![commit_b2.id().clone()]);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_c3.id().clone()))
|
||||
RefTarget::normal(commit_c3.id().clone())
|
||||
);
|
||||
}
|
||||
|
||||
@ -1024,14 +1024,14 @@ fn test_rebase_descendants_basic_branch_update_with_non_local_branch() {
|
||||
let commit_a = graph_builder.initial_commit();
|
||||
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target("main", Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
.set_local_branch_target("main", RefTarget::normal(commit_b.id().clone()));
|
||||
tx.mut_repo().set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(commit_b.id().clone())),
|
||||
RefTarget::normal(commit_b.id().clone()),
|
||||
);
|
||||
tx.mut_repo()
|
||||
.set_tag_target("v1", Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
.set_tag_target("v1", RefTarget::normal(commit_b.id().clone()));
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
@ -1043,16 +1043,16 @@ fn test_rebase_descendants_basic_branch_update_with_non_local_branch() {
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_b2.id().clone()))
|
||||
RefTarget::normal(commit_b2.id().clone())
|
||||
);
|
||||
// The remote branch and tag should not get updated
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_remote_branch("main", "origin"),
|
||||
Some(RefTarget::Normal(commit_b.id().clone()))
|
||||
RefTarget::normal(commit_b.id().clone())
|
||||
);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_tag("v1"),
|
||||
Some(RefTarget::Normal(commit_b.id().clone()))
|
||||
RefTarget::normal(commit_b.id().clone())
|
||||
);
|
||||
|
||||
// Commit B is no longer visible even though the remote branch points to it.
|
||||
@ -1080,7 +1080,7 @@ fn test_rebase_descendants_update_branch_after_abandon() {
|
||||
let commit_a = graph_builder.initial_commit();
|
||||
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target("main", Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
.set_local_branch_target("main", RefTarget::normal(commit_b.id().clone()));
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
@ -1088,7 +1088,7 @@ fn test_rebase_descendants_update_branch_after_abandon() {
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_a.id().clone()))
|
||||
RefTarget::normal(commit_a.id().clone())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -1116,7 +1116,7 @@ fn test_rebase_descendants_update_branches_after_divergent_rewrite() {
|
||||
let commit_a = graph_builder.initial_commit();
|
||||
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target("main", Some(RefTarget::Normal(commit_b.id().clone())));
|
||||
.set_local_branch_target("main", RefTarget::normal(commit_b.id().clone()));
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
@ -1280,7 +1280,7 @@ fn test_rebase_descendants_rewrite_resolves_branch_conflict() {
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_b2.id().clone()))
|
||||
RefTarget::normal(commit_b2.id().clone())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -250,22 +250,22 @@ fn test_merge_views_branches() {
|
||||
let main_branch_alternate_tx0 = write_random_commit(mut_repo, &settings);
|
||||
mut_repo.set_local_branch_target(
|
||||
"main",
|
||||
Some(RefTarget::Normal(main_branch_local_tx0.id().clone())),
|
||||
RefTarget::normal(main_branch_local_tx0.id().clone()),
|
||||
);
|
||||
mut_repo.set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(main_branch_origin_tx0.id().clone())),
|
||||
RefTarget::normal(main_branch_origin_tx0.id().clone()),
|
||||
);
|
||||
mut_repo.set_remote_branch_target(
|
||||
"main",
|
||||
"alternate",
|
||||
Some(RefTarget::Normal(main_branch_alternate_tx0.id().clone())),
|
||||
RefTarget::normal(main_branch_alternate_tx0.id().clone()),
|
||||
);
|
||||
let feature_branch_local_tx0 = write_random_commit(mut_repo, &settings);
|
||||
mut_repo.set_git_ref_target(
|
||||
"feature",
|
||||
Some(RefTarget::Normal(feature_branch_local_tx0.id().clone())),
|
||||
RefTarget::normal(feature_branch_local_tx0.id().clone()),
|
||||
);
|
||||
let repo = tx.commit();
|
||||
|
||||
@ -273,17 +273,17 @@ fn test_merge_views_branches() {
|
||||
let main_branch_local_tx1 = write_random_commit(tx1.mut_repo(), &settings);
|
||||
tx1.mut_repo().set_local_branch_target(
|
||||
"main",
|
||||
Some(RefTarget::Normal(main_branch_local_tx1.id().clone())),
|
||||
RefTarget::normal(main_branch_local_tx1.id().clone()),
|
||||
);
|
||||
tx1.mut_repo().set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(main_branch_origin_tx1.id().clone())),
|
||||
RefTarget::normal(main_branch_origin_tx1.id().clone()),
|
||||
);
|
||||
let feature_branch_tx1 = write_random_commit(tx1.mut_repo(), &settings);
|
||||
tx1.mut_repo().set_local_branch_target(
|
||||
"feature",
|
||||
Some(RefTarget::Normal(feature_branch_tx1.id().clone())),
|
||||
RefTarget::normal(feature_branch_tx1.id().clone()),
|
||||
);
|
||||
tx1.commit();
|
||||
|
||||
@ -291,12 +291,12 @@ fn test_merge_views_branches() {
|
||||
let main_branch_local_tx2 = write_random_commit(tx2.mut_repo(), &settings);
|
||||
tx2.mut_repo().set_local_branch_target(
|
||||
"main",
|
||||
Some(RefTarget::Normal(main_branch_local_tx2.id().clone())),
|
||||
RefTarget::normal(main_branch_local_tx2.id().clone()),
|
||||
);
|
||||
tx2.mut_repo().set_remote_branch_target(
|
||||
"main",
|
||||
"origin",
|
||||
Some(RefTarget::Normal(main_branch_origin_tx1.id().clone())),
|
||||
RefTarget::normal(main_branch_origin_tx1.id().clone()),
|
||||
);
|
||||
tx2.commit();
|
||||
|
||||
@ -310,12 +310,12 @@ fn test_merge_views_branches() {
|
||||
],
|
||||
}),
|
||||
remote_targets: btreemap! {
|
||||
"origin".to_string() => RefTarget::Normal(main_branch_origin_tx1.id().clone()),
|
||||
"alternate".to_string() => RefTarget::Normal(main_branch_alternate_tx0.id().clone()),
|
||||
"origin".to_string() => RefTarget::normal(main_branch_origin_tx1.id().clone()).unwrap(),
|
||||
"alternate".to_string() => RefTarget::normal(main_branch_alternate_tx0.id().clone()).unwrap(),
|
||||
},
|
||||
};
|
||||
let expected_feature_branch = BranchTarget {
|
||||
local_target: Some(RefTarget::Normal(feature_branch_tx1.id().clone())),
|
||||
local_target: RefTarget::normal(feature_branch_tx1.id().clone()),
|
||||
remote_targets: btreemap! {},
|
||||
};
|
||||
assert_eq!(
|
||||
@ -338,24 +338,24 @@ fn test_merge_views_tags() {
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let v1_tx0 = write_random_commit(mut_repo, &settings);
|
||||
mut_repo.set_tag_target("v1.0", Some(RefTarget::Normal(v1_tx0.id().clone())));
|
||||
mut_repo.set_tag_target("v1.0", RefTarget::normal(v1_tx0.id().clone()));
|
||||
let v2_tx0 = write_random_commit(mut_repo, &settings);
|
||||
mut_repo.set_tag_target("v2.0", Some(RefTarget::Normal(v2_tx0.id().clone())));
|
||||
mut_repo.set_tag_target("v2.0", RefTarget::normal(v2_tx0.id().clone()));
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx1 = repo.start_transaction(&settings, "test");
|
||||
let v1_tx1 = write_random_commit(tx1.mut_repo(), &settings);
|
||||
tx1.mut_repo()
|
||||
.set_tag_target("v1.0", Some(RefTarget::Normal(v1_tx1.id().clone())));
|
||||
.set_tag_target("v1.0", RefTarget::normal(v1_tx1.id().clone()));
|
||||
let v2_tx1 = write_random_commit(tx1.mut_repo(), &settings);
|
||||
tx1.mut_repo()
|
||||
.set_tag_target("v2.0", Some(RefTarget::Normal(v2_tx1.id().clone())));
|
||||
.set_tag_target("v2.0", RefTarget::normal(v2_tx1.id().clone()));
|
||||
tx1.commit();
|
||||
|
||||
let mut tx2 = repo.start_transaction(&settings, "test");
|
||||
let v1_tx2 = write_random_commit(tx2.mut_repo(), &settings);
|
||||
tx2.mut_repo()
|
||||
.set_tag_target("v1.0", Some(RefTarget::Normal(v1_tx2.id().clone())));
|
||||
.set_tag_target("v1.0", RefTarget::normal(v1_tx2.id().clone()));
|
||||
tx2.commit();
|
||||
|
||||
let repo = repo.reload_at_head(&settings).unwrap();
|
||||
@ -363,12 +363,12 @@ fn test_merge_views_tags() {
|
||||
removes: vec![v1_tx0.id().clone()],
|
||||
adds: vec![v1_tx1.id().clone(), v1_tx2.id().clone()],
|
||||
};
|
||||
let expected_v2 = RefTarget::Normal(v2_tx1.id().clone());
|
||||
let expected_v2 = RefTarget::normal(v2_tx1.id().clone());
|
||||
assert_eq!(
|
||||
repo.view().tags(),
|
||||
&btreemap! {
|
||||
"v1.0".to_string() => expected_v1,
|
||||
"v2.0".to_string() => expected_v2,
|
||||
"v2.0".to_string() => expected_v2.unwrap(),
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -386,12 +386,12 @@ fn test_merge_views_git_refs() {
|
||||
let main_branch_tx0 = write_random_commit(mut_repo, &settings);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/main",
|
||||
Some(RefTarget::Normal(main_branch_tx0.id().clone())),
|
||||
RefTarget::normal(main_branch_tx0.id().clone()),
|
||||
);
|
||||
let feature_branch_tx0 = write_random_commit(mut_repo, &settings);
|
||||
mut_repo.set_git_ref_target(
|
||||
"refs/heads/feature",
|
||||
Some(RefTarget::Normal(feature_branch_tx0.id().clone())),
|
||||
RefTarget::normal(feature_branch_tx0.id().clone()),
|
||||
);
|
||||
let repo = tx.commit();
|
||||
|
||||
@ -399,12 +399,12 @@ fn test_merge_views_git_refs() {
|
||||
let main_branch_tx1 = write_random_commit(tx1.mut_repo(), &settings);
|
||||
tx1.mut_repo().set_git_ref_target(
|
||||
"refs/heads/main",
|
||||
Some(RefTarget::Normal(main_branch_tx1.id().clone())),
|
||||
RefTarget::normal(main_branch_tx1.id().clone()),
|
||||
);
|
||||
let feature_branch_tx1 = write_random_commit(tx1.mut_repo(), &settings);
|
||||
tx1.mut_repo().set_git_ref_target(
|
||||
"refs/heads/feature",
|
||||
Some(RefTarget::Normal(feature_branch_tx1.id().clone())),
|
||||
RefTarget::normal(feature_branch_tx1.id().clone()),
|
||||
);
|
||||
tx1.commit();
|
||||
|
||||
@ -412,7 +412,7 @@ fn test_merge_views_git_refs() {
|
||||
let main_branch_tx2 = write_random_commit(tx2.mut_repo(), &settings);
|
||||
tx2.mut_repo().set_git_ref_target(
|
||||
"refs/heads/main",
|
||||
Some(RefTarget::Normal(main_branch_tx2.id().clone())),
|
||||
RefTarget::normal(main_branch_tx2.id().clone()),
|
||||
);
|
||||
tx2.commit();
|
||||
|
||||
@ -421,12 +421,12 @@ fn test_merge_views_git_refs() {
|
||||
removes: vec![main_branch_tx0.id().clone()],
|
||||
adds: vec![main_branch_tx1.id().clone(), main_branch_tx2.id().clone()],
|
||||
};
|
||||
let expected_feature_branch = RefTarget::Normal(feature_branch_tx1.id().clone());
|
||||
let expected_feature_branch = RefTarget::normal(feature_branch_tx1.id().clone());
|
||||
assert_eq!(
|
||||
repo.view().git_refs(),
|
||||
&btreemap! {
|
||||
"refs/heads/main".to_string() => expected_main_branch,
|
||||
"refs/heads/feature".to_string() => expected_feature_branch,
|
||||
"refs/heads/feature".to_string() => expected_feature_branch.unwrap(),
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -442,19 +442,19 @@ fn test_merge_views_git_heads() {
|
||||
let mut tx0 = repo.start_transaction(&settings, "test");
|
||||
let tx0_head = write_random_commit(tx0.mut_repo(), &settings);
|
||||
tx0.mut_repo()
|
||||
.set_git_head_target(Some(RefTarget::Normal(tx0_head.id().clone())));
|
||||
.set_git_head_target(RefTarget::normal(tx0_head.id().clone()));
|
||||
let repo = tx0.commit();
|
||||
|
||||
let mut tx1 = repo.start_transaction(&settings, "test");
|
||||
let tx1_head = write_random_commit(tx1.mut_repo(), &settings);
|
||||
tx1.mut_repo()
|
||||
.set_git_head_target(Some(RefTarget::Normal(tx1_head.id().clone())));
|
||||
.set_git_head_target(RefTarget::normal(tx1_head.id().clone()));
|
||||
tx1.commit();
|
||||
|
||||
let mut tx2 = repo.start_transaction(&settings, "test");
|
||||
let tx2_head = write_random_commit(tx2.mut_repo(), &settings);
|
||||
tx2.mut_repo()
|
||||
.set_git_head_target(Some(RefTarget::Normal(tx2_head.id().clone())));
|
||||
.set_git_head_target(RefTarget::normal(tx2_head.id().clone()));
|
||||
tx2.commit();
|
||||
|
||||
let repo = repo.reload_at_head(&settings).unwrap();
|
||||
|
@ -796,7 +796,7 @@ impl WorkspaceCommandHelper {
|
||||
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)?;
|
||||
mut_repo.set_git_head_target(Some(RefTarget::Normal(first_parent_id)));
|
||||
mut_repo.set_git_head_target(RefTarget::normal(first_parent_id));
|
||||
}
|
||||
} else {
|
||||
// The workspace was removed (maybe the user undid the
|
||||
|
@ -156,10 +156,8 @@ fn cmd_branch_create(
|
||||
target_commit.id().hex()
|
||||
));
|
||||
for branch_name in branch_names {
|
||||
tx.mut_repo().set_local_branch_target(
|
||||
branch_name,
|
||||
Some(RefTarget::Normal(target_commit.id().clone())),
|
||||
);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target(branch_name, RefTarget::normal(target_commit.id().clone()));
|
||||
}
|
||||
tx.finish(ui)?;
|
||||
Ok(())
|
||||
@ -203,10 +201,8 @@ fn cmd_branch_set(
|
||||
target_commit.id().hex()
|
||||
));
|
||||
for branch_name in branch_names {
|
||||
tx.mut_repo().set_local_branch_target(
|
||||
branch_name,
|
||||
Some(RefTarget::Normal(target_commit.id().clone())),
|
||||
);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target(branch_name, RefTarget::normal(target_commit.id().clone()));
|
||||
}
|
||||
tx.finish(ui)?;
|
||||
Ok(())
|
||||
|
@ -717,10 +717,8 @@ fn cmd_git_push(
|
||||
change_str.deref()
|
||||
)?;
|
||||
}
|
||||
tx.mut_repo().set_local_branch_target(
|
||||
&branch_name,
|
||||
Some(RefTarget::Normal(commit.id().clone())),
|
||||
);
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target(&branch_name, RefTarget::normal(commit.id().clone()));
|
||||
let branch_target = tx.repo().view().get_branch(&branch_name).unwrap();
|
||||
match classify_branch_update(&branch_name, branch_target, &remote) {
|
||||
Ok(Some(update)) => branch_updates.push((branch_name.clone(), update)),
|
||||
|
Loading…
Reference in New Issue
Block a user