Skip to content

Commit d352431

Browse files
authored
Mark no file with /dev/null to align with git diff (#93)
If you run git diff locally with a staged new file the diff will indicate that the file did not exist before with `--- /dev/null`. I believe this should align with this?
1 parent 85c3199 commit d352431

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class UnifiedDiffUtils {
3333

3434
private static final Pattern UNIFIED_DIFF_CHUNK_REGEXP = Pattern
3535
.compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$");
36+
private static final String NULL_FILE_INDICATOR = "/dev/null";
3637

3738
/**
3839
* Parse the given text in unified format and creates the list of deltas for it.
@@ -143,8 +144,8 @@ public static List<String> generateUnifiedDiff(String originalFileName,
143144
int contextSize) {
144145
if (!patch.getDeltas().isEmpty()) {
145146
List<String> ret = new ArrayList<>();
146-
ret.add("--- " + Optional.ofNullable(originalFileName).orElse(""));
147-
ret.add("+++ " + Optional.ofNullable(revisedFileName).orElse(""));
147+
ret.add("--- " + Optional.ofNullable(originalFileName).orElse(NULL_FILE_INDICATOR));
148+
ret.add("+++ " + Optional.ofNullable(revisedFileName).orElse(NULL_FILE_INDICATOR));
148149

149150
List<AbstractDelta<String>> patchDeltas = new ArrayList<>(
150151
patch.getDeltas());

0 commit comments

Comments
 (0)