Skip to content

Commit

Permalink
Introduce tests for --chmod option
Browse files Browse the repository at this point in the history
  • Loading branch information
jkstrauss committed Feb 9, 2018
1 parent 7e08f52 commit da86750
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
}
}
}
}
}

0 comments on commit da86750

Please sign in to comment.