From 7e08f52e2a281e35da60080e2a8f89b9d7fabd8d Mon Sep 17 00:00:00 2001 From: "Joseph K. Strauss" Date: Sun, 6 Nov 2016 23:35:00 -0500 Subject: [PATCH] Specify chmod as command line option --- .../com/madgag/git/bfg/cli/CLIConfig.scala | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala b/bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala index f11cebe1..cb00b797 100644 --- a/bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala +++ b/bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala @@ -122,6 +122,18 @@ object CLIConfig { c.copy(fixFilenameDuplicatesPreferring = ord) } + fileMatcher( + opt[(String,TextMatcher)]("chmod"), + (t:(String,TextMatcher)) => t match {case (_,tm) => tm} + ). + unbounded. + keyName("<-x|+x>"). + text("change executable mode of files matching glob; option may be specified multiple times, and will be processed in order specified. e.g.,--chmod:-x=*.* --chmod:+x=*.{sh,.pl} will make all files non-executable except *.sh and *.pl files"). + action { (v, c) => c.copy(chmod = c.chmod :+ (v match { + case ("+x", fm) => (ExecutableFile, fm) + case ("-x", fm) => (RegularFile, fm) + case other => throw new IllegalArgumentException(s"'$other' should be '+x' or '-x'") + }))} arg[File]("") optional() action { (x, c) => c.copy(repoLocation = x) } text("file path for Git repository to clean") } @@ -141,7 +153,8 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None, strictObjectChecking: Boolean = false, sensitiveData: Option[Boolean] = None, massiveNonFileObjects: Option[Long] = None, - repoLocation: File = new File(System.getProperty("user.dir"))) { + repoLocation: File = new File(System.getProperty("user.dir")), + chmod: Seq[(BlobFileMode, TextMatcher)] = Seq()) { lazy val gitdir = resolveGitDirFor(repoLocation) @@ -223,7 +236,9 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None, } } - Seq(blobsByIdRemover, blobRemover, fileDeletion, blobTextModifier, lfsBlobConverter).flatten + lazy val chmodCleaner = if(chmod isEmpty) None else Some(new Chmoder(chmod)) + + Seq(blobsByIdRemover, blobRemover, fileDeletion, blobTextModifier, lfsBlobConverter, chmodCleaner).flatten } lazy val definesNoWork = treeBlobCleaners.isEmpty && folderDeletion.isEmpty && treeEntryListCleaners.isEmpty