public void Execute(ICollection <string> args) { if (string.IsNullOrEmpty(repoHelper.Project.Name)) { ch.WriteLine("You need to initialize a repository first.", ConsoleColor.Red); return; } repoHelper.CheckForNewCommitSection(); repoHelper.RemoveRepitionFromNewCommit(); var repoView = repoHelper.GetRepositoryFilesFromXML(); var files = repoHelper.GetFiles(repoHelper.Project.Path); var newCommitFiles = repoHelper.GetNewCommitFiles(); repoHelper.ClearIndexFromRemovedFiles(files.Select(f => f.ShotFileName(repoHelper.Project.Path)), newCommitFiles); foreach (var file in files) { if (repoView.Any(f => f.Name == file.ShotFileName(repoHelper.Project.Path) && f.LAstWriteTime == file.LastWriteTime)) { continue; } if (repoView.Any(f => f.Name == file.ShotFileName(repoHelper.Project.Path) && f.LAstWriteTime != file.LastWriteTime)) { ch.WrtieModified(file.ShotFileName(repoHelper.Project.Path), ConsoleColor.Red); continue; } if (repoView.All(f => f.Name != file.ShotFileName(repoHelper.Project.Path)) && newCommitFiles.All(c => c.Name != file.ShotFileName(repoHelper.Project.Path))) { ch.WrtieAdded(file.ShotFileName(repoHelper.Project.Path), ConsoleColor.Red); continue; } if (newCommitFiles.Any(f => f.Name == file.ShotFileName(repoHelper.Project.Path) && f.LAstWriteTime == file.LastWriteTime)) { var model = newCommitFiles.First(f => f.Name == file.ShotFileName(repoHelper.Project.Path) && f.LAstWriteTime == file.LastWriteTime); ch.WriteLine(string.Format("\t{0}: {1}", model.Status, model.Name), ConsoleColor.Green); continue; } ch.WriteLine(string.Format("\twtf? {0}", file.ShotFileName(repoHelper.Project.Path)), ConsoleColor.DarkCyan); } foreach (var model in repoView) { if (files.All(f => f.ShotFileName(repoHelper.Project.Path) != model.Name) && newCommitFiles.All(c => c.Name != model.Name)) { ch.WrtieRemoved(model.Name, ConsoleColor.Red); } else if (newCommitFiles.Any(c => c.Name == model.Name)) { ch.WrtieRemoved(model.Name, ConsoleColor.Green); } } }
private void AddFile(FileInfo file, ref int fileCounter, bool single = false) { if (IsAlredyInIndex(file, single)) { return; } var version = 1; var status = "added"; var commits = repositoryhHelper.RemoveNewCommitSection(GetCommitsWithFile(file.ShotFileName(repositoryhHelper.Project.Path))); if (commits.Any()) { var maxId = commits.Max(c => Int32.Parse(c.Attribute("id").Value)); var fileMeta = commits.First(x => x.Attribute("id").Value == maxId.ToString()) .Elements("File").First(e => e.Element("fullName").Value == file.ShotFileName(repositoryhHelper.Project.Path)); var date = DateTime.Parse(fileMeta.Element("lwt").Value); if (date == file.LastWriteTime) { if (single) { ch.WriteLine("File wasn't change", ConsoleColor.Red); } return; } version = Int32.Parse(fileMeta.Element("version").Value) + 1; status = "modified"; } var doc = repositoryhHelper.CheckForNewCommitSection(); doc.Descendants("Commit").First(c => c.Attribute("id").Value == "new").Add( new XElement("File", new XElement("name", file.Name), new XElement("fullName", file.ShotFileName(repositoryhHelper.Project.Path)), new XElement("path", file.DirectoryName), new XElement("lwt", file.LastWriteTime), new XElement("directory", file.Directory.Name), new XElement("lenght", file.Length), new XElement("status", status), new XElement("version", version))); ++fileCounter; doc.Save(repositoryhHelper.PathToSave); ch.WriteLine(string.Format("\t {1}: {0}", file.ShotFileName(repositoryhHelper.Project.Path), status), ConsoleColor.Green); }
private void RemoveFile(FileInfo file, bool single = false) { var doc = repositoryhHelper.CheckForNewCommitSection(); var newCommit = doc.Descendants("Commit") .First(e => e.Attribute("id").Value == "new"); if (newCommit.Elements("File").Any(e => e.Element("fullName").Value == file.ShotFileName(repositoryhHelper.Project.Path))) { newCommit.Elements("File") .First(e => e.Element("fullName").Value == file.ShotFileName(repositoryhHelper.Project.Path)).Remove(); doc.Save(repositoryhHelper.PathToSave); ch.WriteLine(string. Format("\t {0} was removed from repository index", file.ShotFileName(repositoryhHelper.Project.Path)), ConsoleColor.Green); } else if (single) { ch.WriteLine(string. Format("\t {0} not in the repository index", file.ShotFileName(repositoryhHelper.Project.Path)), ConsoleColor.Red); } }