diff --git a/mutannot.fsx b/mutannot.fsx index 821447f..60f22ea 100755 --- a/mutannot.fsx +++ b/mutannot.fsx @@ -224,6 +224,26 @@ let tempRoot = Path.Combine(Path.GetTempPath(), $"fscheck-mutants.{Guid.NewGuid( let worktreePath = Path.Combine(tempRoot, "worktree") let patchPath = Path.Combine(tempRoot, "current.patch") +let splitNullSeparated (text: string) = + text.Split('\000', StringSplitOptions.RemoveEmptyEntries) + |> Array.toList + +let repoRelativePath (path: string) = + path.Replace('/', Path.DirectorySeparatorChar) + +let listUntrackedFiles () = + let exitCode, stdout, stderr = captureProcess repoRoot "git" [ "ls-files"; "--others"; "--exclude-standard"; "-z" ] + if exitCode <> 0 then fail stderr + splitNullSeparated stdout + +let copyFileIntoWorktree (relativePath: string) = + let sourcePath = Path.Combine(repoRoot, repoRelativePath relativePath) + let destinationPath = Path.Combine(worktreePath, repoRelativePath relativePath) + let destinationDir = Path.GetDirectoryName destinationPath + if not (String.IsNullOrEmpty destinationDir) then + Directory.CreateDirectory(destinationDir) |> ignore + File.Copy(sourcePath, destinationPath, true) + let cleanup () = if Directory.Exists worktreePath then let _ = captureProcess repoRoot "git" [ "worktree"; "remove"; "--force"; worktreePath ] @@ -233,6 +253,7 @@ let cleanup () = let createWorktree () = Directory.CreateDirectory(tempRoot) |> ignore + let untrackedFiles = listUntrackedFiles () let exitCode, diffText, stderr = captureProcess repoRoot "git" [ "diff"; "--binary"; "HEAD" ] if exitCode <> 0 then fail stderr File.WriteAllText(patchPath, diffText) @@ -248,6 +269,9 @@ let createWorktree () = let exitCode4, _, stderr4 = captureProcess worktreePath "git" [ "apply"; patchPath ] if exitCode4 <> 0 then fail stderr4 + for relativePath in untrackedFiles do + copyFileIntoWorktree relativePath + let testFilter mutation = $"FullyQualifiedName~{mutation.TestName}" let runMutation (mutation: MutationCase) =