aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-07-25 23:25:36 +0200
committerTeddy Wing2020-07-25 23:25:36 +0200
commit74210fa2fd90c5b7cae91f7ea6f4e1f64a597198 (patch)
tree1342c4c93f969a6b5400fe9b8e5c74695946d7dd
parentb4a7561ccc1ed7dab6cd2c786902dec8c4ad9be6 (diff)
downloadgit-suggestion-74210fa2fd90c5b7cae91f7ea6f4e1f64a597198.tar.bz2
Suggestion.apply_to(): Fix single-line patches
Single-line changes weren't getting applied, because if only a single line changed, the `original_start_line` field is null. That caused the first `if` branch to always evaluate to true. Swap the `if` branches to fix this.
-rw-r--r--src/lib.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 682464f..7108395 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -147,12 +147,12 @@ impl Suggestion {
for (i, line) in reader.lines().enumerate() {
match line {
Ok(l) => {
- if self.original_start_line.is_none()
+ if i == self.original_end_line {
+ write!(writer, "{}", self.suggestion()).unwrap();
+ } else if self.original_start_line.is_none()
|| i < self.original_start_line.unwrap()
|| i > self.original_end_line {
writeln!(writer, "{}", l).unwrap();
- } else if i == self.original_end_line {
- write!(writer, "{}", self.suggestion()).unwrap();
}
},
Err(e) => panic!(e),