public void EndTransaction() { var transactionMessage = string.Join(Environment.NewLine, this.transactionMessageList); var statusCommand = new GitCommand(this.BasePath, "status") { new GitCommandItem('s') }; var items = statusCommand.ReadLines(true); if (items.Length != 0) { var commitCommand = new GitCommitCommand(this.BasePath, this.transactionAuthor, transactionMessage); var result = commitCommand.Run(this.logService); this.logService?.Debug(result); var log = GitLogInfo.GetLatestLog(this.BasePath); this.repositoryInfo.Revision = log.CommitID; this.repositoryInfo.ModificationInfo = new SignatureDate(this.transactionAuthor, log.CommitDate); this.SetNotes(this.transactionPropertyList.ToArray()); FileUtility.Delete(this.transactionPatchPath); this.transactionAuthor = null; this.transactionName = null; this.transactionMessageList = null; this.transactionPropertyList = null; this.transactionPatchPath = null; this.Pull(); this.Push(); this.PushNotes(); } else { this.logService?.Debug("repository has no changes."); } }
public LogInfo[] GetLog(string basePath, string repositoryName, string revision) { var baseUri = new Uri(basePath); var repositoryPath = baseUri.LocalPath; var logs = GitLogInfo.GetRepositoryLogs(repositoryPath, repositoryName, revision); return(logs.Select(item => (LogInfo)item).ToArray()); }
public void Commit(string author, string comment, params LogPropertyInfo[] properties) { if (this.transactionName != null) { var diffCommand = new GitCommand(this.BasePath, "diff") { "HEAD", new GitCommandItem("stat"), new GitCommandItem("binary") }; var output = diffCommand.ReadLine(); FileUtility.Prepare(this.transactionPatchPath); File.WriteAllText(this.transactionPatchPath, output); this.transactionMessageList.Add(comment); this.transactionPropertyList.AddRange(properties); return; } try { var statusCommand = new GitCommand(this.BasePath, "status") { new GitCommandItem('s') }; var items = statusCommand.ReadLines(true); if (items.Length != 0) { var authorValue = new GitAuthor(author); GitConfig.SetValue(this.BasePath, "user.email", authorValue.Email == string.Empty ? "<>" : authorValue.Email); GitConfig.SetValue(this.BasePath, "user.name", authorValue.Name); var commitCommand = new GitCommitCommand(this.BasePath, author, comment); var result = commitCommand.Run(this.logService); this.logService?.Debug(result); var log = GitLogInfo.GetLatestLog(this.BasePath); this.repositoryInfo.Revision = log.CommitID; this.repositoryInfo.ModificationInfo = new SignatureDate(author, log.CommitDate); this.SetNotes(properties); //this.isModified = true; //this.Pull(); //this.Push(); //this.PushNotes(); } else { this.logService?.Debug("repository no changes. \"{0}\"", this.BasePath); } } catch (Exception e) { this.logService?.Warn(e); throw; } }
public RepositoryInfo GetRepositoryInfo(string basePath, string repositoryName) { var baseUri = new Uri(basePath); var repositoryInfo = new RepositoryInfo(); var repositoryPath = baseUri.LocalPath; var revisions = GitLogInfo.GetRepositoryRevisions(repositoryPath, repositoryName); var latestLog = GitLogInfo.GetRepositoryLatestLog(repositoryPath, revisions.First()); var refLogItems = GitLogInfo.GetReflogs(basePath, repositoryName); var firstLog = refLogItems.Last(); repositoryInfo.Name = repositoryName; repositoryInfo.Revision = latestLog.CommitID; repositoryInfo.CreationInfo = new SignatureDate(firstLog.Author, firstLog.AuthorDate); repositoryInfo.ModificationInfo = new SignatureDate(latestLog.Author, latestLog.AuthorDate); if (this.HasID(repositoryPath, repositoryName) == false) { this.SetID(repositoryPath, repositoryName, Guid.NewGuid()); } repositoryInfo.ID = this.GetID(repositoryPath, repositoryName); if (this.HasDescription(repositoryPath, repositoryName) == true) { repositoryInfo.Comment = this.GetDescription(repositoryPath, repositoryName); } else { repositoryInfo.Comment = string.Empty; } if (this.HasCreationInfo(repositoryPath, repositoryName) == true) { repositoryInfo.CreationInfo = this.GetCreationInfo(repositoryPath, repositoryName); } return(repositoryInfo); }
public LogInfo[] GetLog(string[] paths, string revision) { var logs = GitLogInfo.GetLogs(this.BasePath, revision, paths); return(logs.Select(item => (LogInfo)item).ToArray()); }