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 authored and josephst committed Jan 23, 2018
1 parent bcd2764 commit edb846c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
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 @@ -38,6 +38,8 @@ class unpackedRepo(filePath: String) extends FlatSpec with Matchers {

def haveFolder(name: String): Matcher[ObjectId] = haveTreeEntry(name, _.isSubtree)

def haveFileMode(name: String, fm: FileMode) = haveTreeEntry(name, (file : TreeWalk) => file.getFileMode == fm && file.getNameString == name)

def haveTreeEntry(name: String, p: TreeWalk => Boolean)= new Matcher[ObjectId] {
def apply(treeish: ObjectId) = {
treeOrBlobPointedToBy(treeish.asRevObject) match {
Expand Down
Binary file not shown.
14 changes: 13 additions & 1 deletion bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package com.madgag.git.bfg.cli

import com.madgag.git._
import com.madgag.git.bfg.cli.test.unpackedRepo
import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.lib.{FileMode, ObjectId}
import org.eclipse.jgit.revwalk.RevCommit
import org.scalatest.{FlatSpec, Inspectors, Matchers, OptionValues}

Expand Down Expand Up @@ -124,5 +124,17 @@ class MainSpec extends FlatSpec with Matchers with OptionValues with Inspectors
run("--fix-filename-duplicates-preferring tree")
}
}

"Corrupt trees bad file modes" should {
"make .pl and .sh files executable and all other files non-executable" in new unpackedRepo("/sample-repos/chmodExample.git.zip") {
ensureRemovalOf(commitHistory(haveFileMode("test.pl", FileMode.REGULAR_FILE).atLeastOnce)) {
ensureRemovalOf(commitHistory(haveFileMode("test.sh", FileMode.REGULAR_FILE).atLeastOnce)) {
ensureRemovalOf(commitHistory(haveFileMode("test.txt", FileMode.EXECUTABLE_FILE).atLeastOnce)) {
run("--no-blob-protection --chmod:-x=*.* --chmod:+x=*.{sh,pl}")
}
}
}
}
}
}

1 change: 1 addition & 0 deletions chmodExample.git
Submodule chmodExample.git added at 1a2b2d

0 comments on commit edb846c

Please sign in to comment.