private void Commit(GitBranches branch, string relativePath, string comment, Author author) { LogTo.Trace("Commit(branch: {0}, relativePath: {1}, comment: {2}, author: {3})", branch, relativePath, comment, author); try { using (var repo = new Repository(WorkingDirectory.FullName)) { repo.Checkout(branch.Name()); repo.Stage(relativePath); repo.Commit(comment, author.ToGitSignature(), Committer()); } } catch (EmptyCommitException) { // We can ignore this exception because there was nothing new to commit. // This can occur if the user uploads the same file. } }
public void ThenTheFileShouldBeCommittedToTheMasterBranchOfTheGitRepository() { var method = _invocationRecorder.CallsTo <IGitRepository>().SingleOrDefault(i => i.Method.Name == "CommitAsync"); method.Should().NotBeNull(); const GitBranches expectedBranch = GitBranches.Master; var expectedRelativePath = string.Format("blog/{0}/{1}.md", _given.Published.ToUniversalTime().DateTime.ToFolders(), _slugFactory.CreateSlug(_given.Title)); var expectedMessage = string.Format("Published blog post '{0}'.", _given.BlogPost.Title); var expectedAuthor = _given.Author; // ReSharper disable once PossibleNullReferenceException var arguments = method.Arguments; arguments[0].Should().Be(expectedBranch); arguments[1].Should().Be(expectedRelativePath); arguments[2].Should().Be(expectedMessage); var actualAuthor = (Author)arguments[3]; actualAuthor.Email.Should().Be(expectedAuthor.Email); actualAuthor.Name.Should().Be(expectedAuthor.Name); actualAuthor.TimeZoneInfo.Should().Be(expectedAuthor.TimeZoneInfo); }
public static string Name(this GitBranches branch) { return(branch.ToString().ToLower()); }
public Task PushAsync(GitBranches branch) { LogTo.Trace("PushAsync(branch: {0})", branch); return(Task.Run(() => Push(branch.Name()))); }
public Task CommitAsync(GitBranches branch, string relativePath, string comment, Author author) { return(Task.Run(() => Commit(branch, relativePath, comment, author))); }