Exemplo n.º 1
0
		void RevertUnimportant(IDestinationDriver driver, string path, string relPath, Action<bool> prepareFileForModifications)
		{
			var relNorm = relPath.ToLowerInvariant().Replace('\\', '/').Trim('/');

			var unimportantPatterns = _unimportants.Where(t => t.Item1.IsMatch(relNorm)).ToArray();

			if (unimportantPatterns.Length == 0)
				return;

			var diff = driver.GetDiff(path);

			var diffLines = diff
				.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
				// skip header up to @@ marker
				.SkipWhile(s => !s.StartsWith("@@"))
				// get only real diff
				.Where(s => s.StartsWith("-") || s.StartsWith("+"))
			;

			// check if all differences matched to any pattern
			if (diffLines.All(diffLine => unimportantPatterns.Any(t => t.Item2.IsMatch(diffLine))))
			{
				// file contains only unimportant changes and will not be included in commit
				prepareFileForModifications(false);

				// revert all unimportant changes
				driver.Revert(path);

				Console.WriteLine("	Skip unimportant: {0}", relPath);
			}
		}