mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-09 22:16:32 +00:00
git_backend: return error when told to write commit without parents
There should be no other commits than the root commit without parents.
This commit is contained in:
parent
8c63fbc4ed
commit
f4374086b3
1 changed files with 14 additions and 2 deletions
|
@ -453,6 +453,11 @@ impl Backend for GitBackend {
|
||||||
let author = signature_to_git(&contents.author);
|
let author = signature_to_git(&contents.author);
|
||||||
let mut committer = signature_to_git(&contents.committer);
|
let mut committer = signature_to_git(&contents.committer);
|
||||||
let message = &contents.description;
|
let message = &contents.description;
|
||||||
|
if contents.parents.is_empty() {
|
||||||
|
return Err(BackendError::Other(
|
||||||
|
"Cannot write a commit with no parents".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
let mut parents = vec![];
|
let mut parents = vec![];
|
||||||
for parent_id in &contents.parents {
|
for parent_id in &contents.parents {
|
||||||
if *parent_id == self.root_commit_id {
|
if *parent_id == self.root_commit_id {
|
||||||
|
@ -735,6 +740,13 @@ mod tests {
|
||||||
committer: create_signature(),
|
committer: create_signature(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// No parents
|
||||||
|
commit.parents = vec![];
|
||||||
|
assert_matches!(
|
||||||
|
backend.write_commit(&commit),
|
||||||
|
Err(BackendError::Other(message)) if message.contains("no parents")
|
||||||
|
);
|
||||||
|
|
||||||
// Only root commit as parent
|
// Only root commit as parent
|
||||||
commit.parents = vec![backend.root_commit_id().clone()];
|
commit.parents = vec![backend.root_commit_id().clone()];
|
||||||
let first_id = backend.write_commit(&commit).unwrap();
|
let first_id = backend.write_commit(&commit).unwrap();
|
||||||
|
@ -786,7 +798,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let commit = Commit {
|
let commit = Commit {
|
||||||
parents: vec![],
|
parents: vec![store.root_commit_id().clone()],
|
||||||
predecessors: vec![],
|
predecessors: vec![],
|
||||||
root_tree: store.empty_tree_id().clone(),
|
root_tree: store.empty_tree_id().clone(),
|
||||||
change_id: ChangeId::new(vec![]),
|
change_id: ChangeId::new(vec![]),
|
||||||
|
@ -810,7 +822,7 @@ mod tests {
|
||||||
let temp_dir = testutils::new_temp_dir();
|
let temp_dir = testutils::new_temp_dir();
|
||||||
let store = GitBackend::init_internal(temp_dir.path());
|
let store = GitBackend::init_internal(temp_dir.path());
|
||||||
let commit1 = Commit {
|
let commit1 = Commit {
|
||||||
parents: vec![],
|
parents: vec![store.root_commit_id().clone()],
|
||||||
predecessors: vec![],
|
predecessors: vec![],
|
||||||
root_tree: store.empty_tree_id().clone(),
|
root_tree: store.empty_tree_id().clone(),
|
||||||
change_id: ChangeId::new(vec![]),
|
change_id: ChangeId::new(vec![]),
|
||||||
|
|
Loading…
Reference in a new issue