b.getString(0, b.size(), false));
}
+ @Test
+ public void testModifyW() throws Exception {
+ ApplyResult result = init("W");
+ assertEquals(1, result.getUpdatedFiles().size());
+ assertEquals(new File(db.getWorkTree(), "W"),
+ result.getUpdatedFiles().get(0));
+ checkFile(new File(db.getWorkTree(), "W"),
+ b.getString(0, b.size(), false));
+ }
+
@Test
public void testModifyX() throws Exception {
ApplyResult result = init("X");
pos++;
break;
case '-':
- if (!newLines.get(hh.getNewStartLine() - 1 + pos).equals(
- hunkLine.substring(1))) {
- throw new PatchApplyException(MessageFormat.format(
- JGitText.get().patchApplyException, hh));
+ if (hh.getNewStartLine() == 0) {
+ newLines.clear();
+ } else {
+ if (!newLines.get(hh.getNewStartLine() - 1 + pos)
+ .equals(hunkLine.substring(1))) {
+ throw new PatchApplyException(MessageFormat.format(
+ JGitText.get().patchApplyException, hh));
+ }
+ newLines.remove(hh.getNewStartLine() - 1 + pos);
}
- newLines.remove(hh.getNewStartLine() - 1 + pos);
break;
case '+':
newLines.add(hh.getNewStartLine() - 1 + pos,
// still there!
sb.append(l).append('\n');
}
- sb.deleteCharAt(sb.length() - 1);
+ if (sb.length() > 0) {
+ sb.deleteCharAt(sb.length() - 1);
+ }
FileWriter fw = new FileWriter(f);
fw.write(sb.toString());
fw.close();