Exemplo n.º 1
0
        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.");
            }
        }
Exemplo n.º 2
0
        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;
            }
        }