public void RevertRepository(string author, string basePath, string repositoryName, string revision, string comment) { var baseUri = new Uri(basePath); var repositoryPath = baseUri.LocalPath; this.CheckoutBranch(repositoryPath, repositoryName); try { var revisionsCommand = new GitCommand(repositoryPath, "log") { GitCommandItem.FromPretty("format:%H"), }; var revisions = revisionsCommand.ReadLines(); if (revisions.Contains(revision) == false) { throw new ArgumentException($"'{revision}' is invalid revision.", nameof(revision)); } foreach (var item in revisions) { if (item == revision) { break; } var revertCommand = new GitCommand(repositoryPath, "revert") { new GitCommandItem('n'), item, }; revertCommand.Run(); } var statusCommand = new GitCommand(repositoryPath, "status") { new GitCommandItem('s') }; var items = statusCommand.ReadLines(true); if (items.Length != 0) { var commitCommand = new GitCommitCommand(basePath, author, comment); commitCommand.Run(); } else { throw new InvalidOperationException("nothing to revert."); } } catch { var abortCommand = new GitCommand(repositoryPath, "revert") { new GitCommandItem("abort"), }; abortCommand.TryRun(); throw; } }
private void SetNotes(params LogPropertyInfo[] properties) { var props = properties.Select(item => (GitPropertyValue)item).ToArray(); var propText = propertySerializer.Serialize(props); var notesCommand = new GitCommand(this.BasePath, "notes") { "add", GitCommandItem.FromMessage(propText), }; notesCommand.Run(this.logService); }
public void CreateRepository(string author, string basePath, string initPath, string comment, params LogPropertyInfo[] properties) { var baseUri = new Uri(basePath); var repositoryPath = baseUri.LocalPath; var repositoryName = Path.GetFileName(initPath); var checkoutCommand = new GitCommand(repositoryPath, "checkout") { new GitCommandItem("orphan"), repositoryName }; checkoutCommand.Run(); var removeCommand = new GitCommand(repositoryPath, "rm") { "-rf", "." }; removeCommand.Run(); DirectoryUtility.Copy(initPath, repositoryPath); foreach (var item in GetEmptyDirectories(repositoryPath)) { File.WriteAllText(Path.Combine(item, KeepExtension), string.Empty); } var statusItems = GitItemStatusInfo.Run(repositoryPath); var addCommand = new GitCommand(repositoryPath, "add"); foreach (var item in statusItems) { if (item.Status == RepositoryItemStatus.Untracked) { addCommand.Add((GitPath)item.Path); } } addCommand.Run(); var commitCommand = new GitCommitCommand(repositoryPath, author, comment); commitCommand.Run(); var props = properties.Select(item => (GitPropertyValue)item).ToArray(); var propText = propertySerializer.Serialize(props); var addNotesCommand = new GitCommand(basePath, "notes") { "add", GitCommandItem.FromMessage(propText) }; addNotesCommand.Run(); this.SetID(repositoryPath, repositoryName, Guid.NewGuid()); this.SetDescription(repositoryPath, repositoryName, comment); }
public void InitializeRepository(string basePath, string repositoryPath, params LogPropertyInfo[] properties) { var cloneCommand = new GitCommand(null, "clone") { (GitPath)repositoryPath, (GitPath)basePath, }; if (cloneCommand.TryRun() == true) { var fetchCommand = new GitCommand(basePath, "fetch") { "origin", "refs/notes/commits:refs/notes/commits", }; fetchCommand.Run(); GitConfig.SetValue(basePath, "receive.denyCurrentBranch", "ignore"); return; } var initCommand = new GitCommand(null, "init") { (GitPath)basePath }; initCommand.Run(); var configCommand = new GitCommand(basePath, "config") { "receive.denyCurrentBranch", "ignore" }; configCommand.Run(); DirectoryUtility.Copy(repositoryPath, basePath); foreach (var item in GetEmptyDirectories(basePath)) { File.WriteAllText(Path.Combine(item, KeepExtension), string.Empty); } var query = from item in DirectoryUtility.GetAllFiles(basePath, "*", true) select(GitPath) PathUtility.GetFullPath(item); var itemList = query.ToList(); var addCommand = new GitAddCommand(basePath, query.ToArray()); addCommand.Run(); var commitCommand = new GitCommitCommand(basePath, Environment.UserName, "first commit"); commitCommand.Run(); var props = properties.Select(item => (GitPropertyValue)item).ToArray(); var propText = propertySerializer.Serialize(props); var addNotesCommand = new GitCommand(basePath, "notes") { "add", GitCommandItem.FromMessage(propText) }; addNotesCommand.Run(); this.SetID(basePath, "master", Guid.NewGuid()); }