summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-06-11 13:16:18 +0200
committerThomas Wolf <thomas.wolf@paranor.ch>2019-06-11 14:42:46 +0200
commit1cfcde48534dcc9510e6e58d422a78fcd156c85f (patch)
treeb85cc75f4aa2fd0eb2061908481c679409d25dde /org.eclipse.jgit
parentfd8d779b5eec614d2cb5a611f2e36f522b34a439 (diff)
downloadjgit-1cfcde48534dcc9510e6e58d422a78fcd156c85f.tar.gz
jgit-1cfcde48534dcc9510e6e58d422a78fcd156c85f.zip
Handle missing "ours" stage in WorkingTreeIterator.hasCrLfInIndex()
In a delete-modify conflict with the deletion as "ours" there may be no stage 2 in the index. Add appropriate null checks. Add a new test for this case, and verify that the file gets added with a single LF after conflict resolution with core.autocrlf=true. This matches the behavior of canonical git for this case. Bug: 547724 Change-Id: I1bafdb83d9b78bf85294c78325e818e72fae53bc Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java25
1 files changed, 15 insertions, 10 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
index c0c24872b2..3efa66459c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -1516,6 +1516,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
ObjectId blobId = entry.getObjectId();
if (entry.getStage() > 0
&& entry.getStage() != DirCacheEntry.STAGE_2) {
+ blobId = null;
// Merge conflict: check ours (stage 2)
byte[] name = entry.getRawPath();
int i = 0;
@@ -1523,7 +1524,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
dirCache.next(1);
i++;
entry = dirCache.getDirCacheEntry();
- if (!Arrays.equals(name, entry.getRawPath())) {
+ if (entry == null
+ || !Arrays.equals(name, entry.getRawPath())) {
break;
}
if (entry.getStage() == DirCacheEntry.STAGE_2) {
@@ -1533,17 +1535,20 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
}
dirCache.back(i);
}
- try (ObjectReader reader = repository.newObjectReader()) {
- ObjectLoader loader = reader.open(blobId, Constants.OBJ_BLOB);
- try {
- return RawText.isCrLfText(loader.getCachedBytes());
- } catch (LargeObjectException e) {
- try (InputStream in = loader.openStream()) {
- return RawText.isCrLfText(in);
+ if (blobId != null) {
+ try (ObjectReader reader = repository.newObjectReader()) {
+ ObjectLoader loader = reader.open(blobId,
+ Constants.OBJ_BLOB);
+ try {
+ return RawText.isCrLfText(loader.getCachedBytes());
+ } catch (LargeObjectException e) {
+ try (InputStream in = loader.openStream()) {
+ return RawText.isCrLfText(in);
+ }
}
+ } catch (IOException e) {
+ // Ignore and return false below
}
- } catch (IOException e) {
- // Ignore and return false below
}
}
return false;