mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-01 00:50:57 +00:00
conflicts: don't panic when a conflict marker is missing removes
Closes #2611
This commit is contained in:
parent
4f656f3e02
commit
3133534b32
3 changed files with 11 additions and 5 deletions
|
@ -22,6 +22,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|||
|
||||
### Fixed bugs
|
||||
|
||||
* Fixed panic when parsing invalid conflict markers of a particular form.
|
||||
([#2611](https://github.com/martinvonz/jj/pull/2611))
|
||||
|
||||
## [0.21.0] - 2024-09-04
|
||||
|
||||
### Breaking changes
|
||||
|
|
|
@ -456,7 +456,7 @@ fn parse_conflict_hunk(input: &[u8]) -> Merge<BString> {
|
|||
removes.last_mut().unwrap().extend_from_slice(rest);
|
||||
adds.last_mut().unwrap().extend_from_slice(rest);
|
||||
} else {
|
||||
// Doesn't look like a conflict
|
||||
// Doesn't look like a valid conflict
|
||||
return Merge::resolved(BString::new(vec![]));
|
||||
}
|
||||
}
|
||||
|
@ -467,13 +467,18 @@ fn parse_conflict_hunk(input: &[u8]) -> Merge<BString> {
|
|||
adds.last_mut().unwrap().extend_from_slice(line);
|
||||
}
|
||||
State::Unknown => {
|
||||
// Doesn't look like a conflict
|
||||
// Doesn't look like a valid conflict
|
||||
return Merge::resolved(BString::new(vec![]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Merge::from_removes_adds(removes, adds)
|
||||
if adds.len() == removes.len() + 1 {
|
||||
Merge::from_removes_adds(removes, adds)
|
||||
} else {
|
||||
// Doesn't look like a valid conflict
|
||||
Merge::resolved(BString::new(vec![]))
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses conflict markers in `content` and returns an updated version of
|
||||
|
|
|
@ -750,8 +750,6 @@ fn test_parse_conflict_wrong_arity() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// TODO: Should *not* panic
|
||||
#[should_panic]
|
||||
fn test_parse_conflict_malformed_missing_removes() {
|
||||
// Right number of adds but missing removes
|
||||
assert_eq!(
|
||||
|
|
Loading…
Reference in a new issue