diff --git a/bfg-test/src/main/scala/com/madgag/git/bfg/test/unpackedRepo.scala b/bfg-test/src/main/scala/com/madgag/git/bfg/test/unpackedRepo.scala index 673b1f8b..c86a675f 100644 --- a/bfg-test/src/main/scala/com/madgag/git/bfg/test/unpackedRepo.scala +++ b/bfg-test/src/main/scala/com/madgag/git/bfg/test/unpackedRepo.scala @@ -4,7 +4,7 @@ import com.madgag.git._ import com.madgag.git.test._ import org.eclipse.jgit.internal.storage.file.{GC, ObjectDirectory} import org.eclipse.jgit.lib.Constants.OBJ_BLOB -import org.eclipse.jgit.lib.{ObjectId, ObjectReader, Repository} +import org.eclipse.jgit.lib.{ObjectId, ObjectReader, Repository, FileMode} import org.eclipse.jgit.revwalk.{RevCommit, RevTree} import org.eclipse.jgit.treewalk.TreeWalk import org.scalatest.matchers.{MatchResult, Matcher} @@ -58,6 +58,9 @@ class unpackedRepo(filePath: String) extends FlatSpec with Matchers { } } + def haveFileMode(name: String, fm: FileMode): Matcher[ObjectId] = + haveTreeEntry(name, (file : TreeWalk) => file.getFileMode == fm && file.getNameString == name) + def treeEntryNames(t: RevTree, p: TreeWalk => Boolean): Seq[String] = t.walk(postOrderTraversal = true).withFilter(p).map(_.getNameString).toList diff --git a/bfg/src/test/resources/sample-repos/chmodExample.git.zip b/bfg/src/test/resources/sample-repos/chmodExample.git.zip new file mode 100644 index 00000000..36ff8d6a Binary files /dev/null and b/bfg/src/test/resources/sample-repos/chmodExample.git.zip differ diff --git a/bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala b/bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala index 1a7f684e..e579fb51 100644 --- a/bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala +++ b/bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala @@ -25,6 +25,7 @@ import com.madgag.git.bfg.cli.test.unpackedRepo import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.revwalk.RevCommit import org.scalatest.{FlatSpec, Inspectors, Matchers, OptionValues} +import org.eclipse.jgit.lib.FileMode import scalax.file.ImplicitConversions._ import scalax.file.Path @@ -124,5 +125,15 @@ class MainSpec extends FlatSpec with Matchers with OptionValues with Inspectors run("--fix-filename-duplicates-preferring tree") } } + + "Corrupt trees containing bad file modes" should "make .pl and .sh files executable and all other files non-executable" in new unpackedRepo("/sample-repos/chmodExample.git.zip") { + ensureRemovalFrom(commitHist()).ofCommitsThat(haveFileMode("test.pl", FileMode.REGULAR_FILE)) { + ensureRemovalFrom(commitHist()).ofCommitsThat(haveFileMode("test.sh", FileMode.REGULAR_FILE)) { + ensureRemovalFrom(commitHist()).ofCommitsThat(haveFileMode("test.txt", FileMode.EXECUTABLE_FILE)) { + run("--no-blob-protection --chmod:-x=*.* --chmod:+x=*.{sh,pl}") + } + } + } + } }