| 198 | } |
| 199 | |
| 200 | func (self *Patch) IsSingleHunkForWholeFile() bool { |
| 201 | if len(self.hunks) != 1 { |
| 202 | return false |
| 203 | } |
| 204 | |
| 205 | // We consider a patch to be a single hunk for the whole file if it has only additions or |
| 206 | // deletions but not both, and no context lines. This not quite correct, because it will also |
| 207 | // return true for a block of added or deleted lines if the diff context size is 0, but in this |
| 208 | // case you wouldn't be able to stage things anyway, so it doesn't matter. |
| 209 | bodyLines := self.hunks[0].bodyLines |
| 210 | return nLinesWithKind(bodyLines, []PatchLineKind{DELETION, CONTEXT}) == 0 || |
| 211 | nLinesWithKind(bodyLines, []PatchLineKind{ADDITION, CONTEXT}) == 0 |
| 212 | } |