/// <summary> /// Executes the /// <code>clean</code> /// command with all the options and parameters /// collected by the setter methods of this class. Each instance of this /// class should only be used for one invocation of the command (means: one /// call to /// <see cref="Call()">Call()</see> /// ) /// </summary> /// <returns>a set of strings representing each file cleaned.</returns> public override ICollection <string> Call() { ICollection <string> files = new TreeSet <string>(); try { StatusCommand command = new StatusCommand(repo); Status status = command.Call(); foreach (string file in status.GetUntracked()) { if (paths.IsEmpty() || paths.Contains(file)) { if (!dryRun) { FileUtils.Delete(new FilePath(repo.WorkTree, file)); } files.AddItem(file); } } } catch (IOException e) { throw new JGitInternalException(e.Message, e); } return(files); }
public virtual void TestClean() { // create status StatusCommand command = git.Status(); Status status = command.Call(); ICollection <string> files = status.GetUntracked(); NUnit.Framework.Assert.IsTrue(files.Count > 0); // run clean ICollection <string> cleanedFiles = git.Clean().Call(); status = git.Status().Call(); files = status.GetUntracked(); NUnit.Framework.Assert.AreEqual(0, files.Count); NUnit.Framework.Assert.IsTrue(cleanedFiles.Contains("File2.txt")); NUnit.Framework.Assert.IsTrue(cleanedFiles.Contains("File3.txt")); }
public virtual void TestCleanWithPaths() { // create status StatusCommand command = git.Status(); Status status = command.Call(); ICollection <string> files = status.GetUntracked(); NUnit.Framework.Assert.IsTrue(files.Count > 0); // run clean with setPaths ICollection <string> paths = new TreeSet <string>(); paths.AddItem("File3.txt"); ICollection <string> cleanedFiles = git.Clean().SetPaths(paths).Call(); status = git.Status().Call(); files = status.GetUntracked(); NUnit.Framework.Assert.AreEqual(1, files.Count); NUnit.Framework.Assert.IsTrue(cleanedFiles.Contains("File3.txt")); NUnit.Framework.Assert.IsFalse(cleanedFiles.Contains("File2.txt")); }