private int ExecuteFixAdd(GitIgnoreCommand command, Repository repo) { int retval = 0; var filetocheck = repo.File; if (File.Exists(filetocheck)) { var lines = File.ReadAllLines(filetocheck).ToList(); retval = FixNuGet(command, lines, filetocheck, retval); } else { Writer.WriteRed("No .gitignore in " + repo.GitRepo + "\nUse IFix gitignore -r -f to retrieve the standard gitignore"); if (GitIgnoreCommand.Fix || GitIgnoreCommand.Add) { File.WriteAllLines(filetocheck, stdGitIgnore); Writer.Write("Added " + filetocheck); } retval++; } return(retval); }
public int Execute(GitIgnoreCommand command) { #if DEBUG Console.Write("A chance to attach the debugger"); Console.ReadKey(); #endif GitIgnoreCommand = command; int retval = 0; if (!Repositories.Any()) { Writer.Write("No git subfolders found. Run IFix from either above your git repos or from within root folder of your git repo."); } foreach (var repository in Repositories) { int thisrepo = 0; Writer.Write("Checking: " + repository.GitRepo); if (GitIgnoreCommand.Replace) { ExecuteReplace(repository); } else if (GitIgnoreCommand.Merge) { thisrepo += ExecuteMerge(repository); } else if ((GitIgnoreCommand.Check || GitIgnoreCommand.Fix || GitIgnoreCommand.Add)) { thisrepo += ExecuteFixAdd(command, repository); } if (thisrepo == 0 && !command.Verbose) { Writer.WriteGreen("-->is Ok<--"); } retval += thisrepo; } return(retval); }
/// <summary> /// For use within IFix, from other commands, only works on current directory. Requires that the Fix option is set /// </summary> /// <param name="gitIgnoreCommand"></param> public GitIgnore(GitIgnoreCommand gitIgnoreCommand) { GitIgnoreCommand = gitIgnoreCommand; RetrieveStdGitIgnore(); }
private int FixNuGet(GitIgnoreCommand command, ICollection <string> lines, string filetocheck, int retval) { var outlines = new List <string>(); bool fix = false; bool green = true; if (!CheckIfNuGetPackages(lines, GitIgnoreCommand.Strict, GitIgnoreCommand.LatestGitVersion)) { if (!GitIgnoreCommand.Strict) { Writer.WriteRed( "Missing 'packages' or 'packages/' or 'packages/*' or '**/packages/*' in ignorelist for " + filetocheck); } else { if (!GitIgnoreCommand.LatestGitVersion) { Writer.WriteRed("Missing either/or both '**/packages/*' and 'packages/*' in ignorelist for " + filetocheck); } else { Writer.WriteRed("Missing '**/packages/*' in ignorelist for " + filetocheck); } } if (GitIgnoreCommand.Fix && !GitIgnoreCommand.Add) { outlines.AddRange(AddOnlyMissingInfo(lines, command.LatestGitVersion)); lines = outlines; fix = true; } retval++; green = false; } else { var reincludes = CheckIfNuGetPackagesAllowReincludes(lines); if (!reincludes && command.Verbose) { Writer.Write("Warning: Reincludes does not work with this pattern '" + GetNuGetPackageCommand(lines) + "'"); Writer.Write("See http://geekswithblogs.net/terje/archive/2014/07/03/gitignorendashhow-to-exclude-nuget-packages-at-any-level-and-make.aspx for more information"); } } if (!CheckIfVS2015Files(lines)) { Writer.WriteRed("Missing node_modules in " + filetocheck); if (GitIgnoreCommand.Fix && !GitIgnoreCommand.Add) { outlines.AddRange(new List <string> { "node_modules/" }); fix = true; } green = false; retval++; } if (green) { Writer.WriteGreen("Ok : " + filetocheck); } if (!fix) { return(retval); } File.WriteAllLines(filetocheck, outlines); Writer.Write("Fixed " + filetocheck); return(retval); }