diff --git a/platform/util/src/com/intellij/util/LineSeparator.java b/platform/util/src/com/intellij/util/LineSeparator.java index 32746332eee8..7d65765fff85 100644 --- a/platform/util/src/com/intellij/util/LineSeparator.java +++ b/platform/util/src/com/intellij/util/LineSeparator.java @@ -15,6 +15,8 @@ */ package com.intellij.util; +import com.intellij.openapi.util.SystemInfo; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -52,4 +54,12 @@ public enum LineSeparator { public static boolean knownAndDifferent(@Nullable LineSeparator separator1, @Nullable LineSeparator separator2) { return separator1 != null && separator2 != null && !separator1.equals(separator2); } + + @NotNull + public static LineSeparator getSystemLineSeparator() { + if (SystemInfo.isWindows) { + return CRLF; + } + return LF; + } } diff --git a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy index 683623b834a0..69346105daa3 100644 --- a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy +++ b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy @@ -351,15 +351,12 @@ class GitBranchWorkerTest { assertCurrentBranch("feature"); cd myUltimate def actual = cat(localChanges[0]) - def expectedContent = """line with branch changes -common content -common content -common content -line with master changes -""" - assertEquals("Content doesn't match", StringUtil.convertLineSeparators(expectedContent, LineSeparator.CRLF.separatorString), actual) + def expectedContent = LOCAL_CHANGES_OVERWRITTEN_BY.branchLine + + LOCAL_CHANGES_OVERWRITTEN_BY.initial + + LOCAL_CHANGES_OVERWRITTEN_BY.masterLine; + assertContent(expectedContent, actual) } - + @Test public void "agree to smart merge should smart merge"() { def localChanges = agree_to_smart_operation("merge", @@ -367,13 +364,10 @@ line with master changes cd myUltimate def actual = cat(localChanges[0]) - def expectedContent = """line with branch changes -common content -common content -common content -line with master changes -""" - assertEquals("Content doesn't match", StringUtil.convertLineSeparators(expectedContent, LineSeparator.CRLF.separatorString), actual) + def expectedContent = LOCAL_CHANGES_OVERWRITTEN_BY.branchLine + + LOCAL_CHANGES_OVERWRITTEN_BY.initial + + LOCAL_CHANGES_OVERWRITTEN_BY.masterLine; + assertEquals("Content doesn't match", StringUtil.convertLineSeparators(expectedContent, LineSeparator.getSystemLineSeparator().separatorString), actual) } Collection agree_to_smart_operation(String operation, String expectedSuccessMessage) { @@ -776,6 +770,12 @@ line with master changes assertEquals "Content doesn't match", content, cat(path) } + private static void assertContent(String expectedContent, String actual) { + assertEquals "Content doesn't match", + StringUtil.convertLineSeparators(expectedContent, LineSeparator.getSystemLineSeparator().separatorString), + actual + } + // TODO Somehow I wasn't able to make dynamic partial implementations, because both overloaded notifySuccess() methods are needed, // therefore there are duplicate entries in the map => only one method gets implemented. class AgreeToSmartOperationTestUiHandler implements GitBranchUiHandler { diff --git a/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy b/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy index b9b25b28decb..1e5993d37fad 100644 --- a/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy +++ b/plugins/git4idea/tests/git4idea/test/GitScenarios.groovy @@ -30,14 +30,14 @@ class GitScenarios { private static final String BRANCH_FOR_UNMERGED_CONFLICTS = "unmerged_files_branch_" + Math.random(); - private static final def LOCAL_CHANGES_OVERWRITTEN_BY = [ + static final def LOCAL_CHANGES_OVERWRITTEN_BY = [ initial: """common content common content common content """, - branchLine: "line with branch changes", - masterLine: "line with master changes" + branchLine: "line with branch changes\n", + masterLine: "line with master changes\n" ] /** @@ -139,7 +139,7 @@ common content def prepend(String fileName, String content) { def previousContent = cat(fileName) - new File(myCurrentDir, fileName).withWriter("UTF-8") { it.write(content + "\n" + previousContent) } + new File(myCurrentDir, fileName).withWriter("UTF-8") { it.write(content + previousContent) } } }