diff --git a/Git/Project.cs b/Git/Project.cs index 0e9437e..5158c72 100644 --- a/Git/Project.cs +++ b/Git/Project.cs @@ -16,11 +16,16 @@ public Project(string gitPath) GitPath = gitPath; } - public void Init(string repository) + public void Init(string repository, string authorName, string authorEmail) { if (!Directory.Exists(GitPath)) Directory.CreateDirectory(GitPath); if (!File.Exists(Path.Join(GitPath, ".git", "config"))) RunCommand($"init"); + Environment.SetEnvironmentVariable("GIT_AUTHOR_NAME", authorName); + Environment.SetEnvironmentVariable("GIT_AUTHOR_EMAIL", authorEmail); + Environment.SetEnvironmentVariable("GIT_COMMITTER_NAME", authorName); + Environment.SetEnvironmentVariable("GIT_COMMITTER_EMAIL", authorEmail); + RunCommandIgnoreErrors($"config remove-section remote.origin"); RunCommand($"remote add origin --mirror=fetch {repository}"); } @@ -97,16 +102,12 @@ public string Describe(string options) throw new ApplicationException("Unable to describe commit"); } - public string CommitTree(string authorName, string authorEmail, string treeRef, IEnumerable parentRefs, string message) + public string CommitTree(string treeRef, IEnumerable parentRefs, string message) { var tempFile = Path.GetTempFileName(); File.WriteAllText(tempFile, message); try { - Environment.SetEnvironmentVariable("GIT_AUTHOR_NAME", authorName); - Environment.SetEnvironmentVariable("GIT_AUTHOR_EMAIL", authorEmail); - Environment.SetEnvironmentVariable("GIT_COMMITTER_NAME", authorName); - Environment.SetEnvironmentVariable("GIT_COMMITTER_EMAIL", authorEmail); var parents = String.Join(" ", parentRefs.Select(parentRef => $"-p {parentRef}")); foreach (var line in GetCommandOutput($"commit-tree {treeRef} {parents} -F {tempFile}")) { diff --git a/Program.cs b/Program.cs index f23cd58..45059f3 100644 --- a/Program.cs +++ b/Program.cs @@ -94,7 +94,7 @@ static async Task AsyncMain(IConfigurationRoot config) Console.WriteLine("Preparing repository..."); var git = new Git.Project(GetGitPath()); - git.Init($"git@github.com:{gitHubConfig["organization"]}/{gitHubConfig["repository"]}.git"); + git.Init($"git@github.com:{gitHubConfig["organization"]}/{gitHubConfig["repository"]}.git", gitHubConfig["mergeAuthorName"], gitHubConfig["mergeAuthorEmail"]); git.Fetch(); git.ResetHard(); git.Clean(); @@ -162,7 +162,7 @@ static async Task AsyncMain(IConfigurationRoot config) git.GetAbbreviatedCommit($"pull/{pr.Number}/head") ))) ); - var newMergeBranchCommit = git.CommitTree(gitHubConfig["mergeAuthorName"], gitHubConfig["mergeAuthorEmail"], $"{autoMergeCommit}^{{tree}}", mergeBranchParents, newMergeBranchMessage); + var newMergeBranchCommit = git.CommitTree($"{autoMergeCommit}^{{tree}}", mergeBranchParents, newMergeBranchMessage); git.SetBranchRef(gitHubConfig["mergeBranch"], newMergeBranchCommit); git.Checkout(gitHubConfig["mergeBranch"]); var newMergeBranchVersion = String.Format(