Skip to content

Commit 47c30fb

Browse files
committed
Add explicit test for newline-preservation
#485 reported that the BFG wasn't preserving CR/LF newlines when using `--replace-text` (even modifying newlines on unaffected files). This commit adds some a couple of explicit tests, verifying that the BFG does indeed preserve newlines.
1 parent ed1d376 commit 47c30fb

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ repo.git.zip
1010
**/.settings
1111
.bsp
1212

13+
.DS_Store
1314
test-results/
Binary file not shown.

bfg-library/src/test/scala/com/madgag/git/bfg/cleaner/RepoRewriteSpec.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class RepoRewriteSpec extends AnyFlatSpec with Matchers {
130130
val filename = s"$fileNamePrefix-ORIGINAL.$fileNamePostfix"
131131
val beforeFile = s"$parentPath/$filename"
132132
val afterFile = s"$parentPath/$fileNamePrefix-MODIFIED-$beforeAndAfter.$fileNamePostfix"
133-
// val dirtyFile = repo.resolve(s"master:$beforeFile")
134133

135134
val blobTextModifier = new BlobTextModifier {
136135
def lineCleanerFor(entry: TreeBlobEntry) = Some(quote(before).r --> (_ => after))
@@ -146,10 +145,8 @@ class RepoRewriteSpec extends AnyFlatSpec with Matchers {
146145
expectedFile should not be null
147146

148147
implicit val threadLocalObjectReader = repo.getObjectDatabase.threadLocalResources.reader()
149-
// val dirty = dirtyFile.open.getBytes
150148
val cleaned = cleanedFile.open.getBytes
151149
val expected = expectedFile.open.getBytes
152-
// val dirtyStr = new String(dirty)
153150
val cleanedStr = new String(cleaned)
154151
val expectedStr = new String(expected)
155152

@@ -167,4 +164,10 @@ class RepoRewriteSpec extends AnyFlatSpec with Matchers {
167164

168165
it should "handle converting Windows newlines to Unix" in textReplacementOf("newlines", "windows", "txt", "\r\n", "\n")
169166

167+
it should "handle a file that uses LF for newlines" in
168+
textReplacementOf("newlines", "using-LF", "txt", "file", "blob")
169+
170+
it should "handle a file that uses CRLF for newlines" in
171+
textReplacementOf("newlines", "using-CRLF", "txt", "file", "blob")
172+
170173
}

bfg/build.sbt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ packageOptions in (Compile, packageBin) +=
1717
Package.ManifestAttributes( "Main-Class-After-UseNewerJava-Check" -> "com.madgag.git.bfg.cli.Main" )
1818

1919
// note you don't want the jar name to collide with the non-assembly jar, otherwise confusion abounds.
20-
assemblyJarName in assembly := s"${name.value}-${version.value}-${gitDescription.value}${jgitVersionOverride.map("-jgit-" + _).mkString}.jar"
20+
assembly / assemblyJarName := s"${name.value}-${version.value}-${gitDescription.value}${jgitVersionOverride.map("-jgit-" + _).mkString}.jar"
2121

2222
buildInfoKeys := Seq[BuildInfoKey](version, scalaVersion, gitDescription)
2323

@@ -37,7 +37,7 @@ cliUsageDump := {
3737
val scalaRun = new ForkRun(ForkOptions().withOutputStrategy(CustomOutput(new FileOutputStream(usageDumpFile))))
3838

3939
val mainClassName = (mainClass in (Compile, run)).value getOrElse sys.error("No main class detected.")
40-
val classpath = Attributed.data((fullClasspath in Runtime).value)
40+
val classpath = Attributed.data((Runtime / fullClasspath).value)
4141
val args = Seq.empty
4242

4343
scalaRun.run(mainClassName, classpath, args, streams.value.log).failed foreach (sys error _.getMessage)
@@ -64,12 +64,12 @@ import Tests._
6464
}
6565
}
6666

67-
testGrouping in Test := isolateTestsWhichRequireTheirOwnJvm( (definedTests in Test).value )
67+
Test / testGrouping := isolateTestsWhichRequireTheirOwnJvm( (Test / definedTests).value )
6868
}
6969

70-
fork in Test := true // JGit uses static (ie JVM-wide) config
70+
Test / fork := true // JGit uses static (ie JVM-wide) config
7171

72-
logBuffered in Test := false
72+
Test / logBuffered := false
7373

74-
parallelExecution in Test := false
74+
Test / parallelExecution := false
7575

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "1.14.1-SNAPSHOT"
1+
ThisBuild / version := "1.14.1-SNAPSHOT"

0 commit comments

Comments
 (0)