(self)
| 132 | |
| 133 | # ------------- public entry point -------------------------------------- # |
| 134 | def parse(self) -> None: |
| 135 | while not self.is_done(("*** End Patch",)): |
| 136 | # ---------- UPDATE ---------- # |
| 137 | path = self.read_str("*** Update File: ") |
| 138 | if path: |
| 139 | if path in self.patch.actions: |
| 140 | raise DiffError(f"Duplicate update for file: {path}") |
| 141 | move_to = self.read_str("*** Move to: ") |
| 142 | if path not in self.current_files: |
| 143 | raise DiffError(f"Update File Error - missing file: {path}") |
| 144 | text = self.current_files[path] |
| 145 | action = self._parse_update_file(text) |
| 146 | action.move_path = move_to or None |
| 147 | self.patch.actions[path] = action |
| 148 | continue |
| 149 | |
| 150 | # ---------- DELETE ---------- # |
| 151 | path = self.read_str("*** Delete File: ") |
| 152 | if path: |
| 153 | if path in self.patch.actions: |
| 154 | raise DiffError(f"Duplicate delete for file: {path}") |
| 155 | if path not in self.current_files: |
| 156 | raise DiffError(f"Delete File Error - missing file: {path}") |
| 157 | self.patch.actions[path] = PatchAction(type=ActionType.DELETE) |
| 158 | continue |
| 159 | |
| 160 | # ---------- ADD ---------- # |
| 161 | path = self.read_str("*** Add File: ") |
| 162 | if path: |
| 163 | if path in self.patch.actions: |
| 164 | raise DiffError(f"Duplicate add for file: {path}") |
| 165 | if path in self.current_files: |
| 166 | raise DiffError(f"Add File Error - file already exists: {path}") |
| 167 | self.patch.actions[path] = self._parse_add_file() |
| 168 | continue |
| 169 | |
| 170 | raise DiffError(f"Unknown line while parsing: {self._cur_line()}") |
| 171 | |
| 172 | if not self.startswith("*** End Patch"): |
| 173 | raise DiffError("Missing *** End Patch sentinel") |
| 174 | self.index += 1 # consume sentinel |
| 175 | |
| 176 | # ------------- section parsers ---------------------------------------- # |
| 177 | def _parse_update_file(self, text: str) -> PatchAction: |
no test coverage detected