Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Git/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand Down Expand Up @@ -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<string> parentRefs, string message)
public string CommitTree(string treeRef, IEnumerable<string> 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}"))
{
Expand Down
4 changes: 2 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
Loading