Skip to content

Commit

Permalink
Fix pull rebases
Browse files Browse the repository at this point in the history
So apparently, git pull --rebase will ask for committer information mid-rebase if not available.

Yeah that's why changelogs have been broken for the past 5 days.
  • Loading branch information
PJB3005 committed Jan 9, 2024
1 parent 47ac8d3 commit 3d6971f
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions SS14.Changelog/Services/ChangelogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,12 @@ await WaitForSuccessAsync(new ProcessStartInfo
WorkingDirectory = repo
});

var commitCommand = new ProcessStartInfo
await WaitForSuccessAsync(GitCommitCommand(new ProcessStartInfo
{
FileName = "git",
ArgumentList = {"commit", "-m", "Automatic changelog update"},
WorkingDirectory = repo
};

if (cfg.CommitAuthorName is { } authorName)
{
commitCommand.ArgumentList.Insert(0, "-c");
commitCommand.ArgumentList.Insert(1, "user.name=" + authorName);
}

if (cfg.CommitAuthorEmail is { } authorEmail)
{
commitCommand.ArgumentList.Insert(0, "-c");
commitCommand.ArgumentList.Insert(1, "user.email=" + authorEmail);
}

await WaitForSuccessAsync(commitCommand);
}));

// If we merge something *while* the changelog is running then the push would fail.
// So if the push fails we pull --rebase again to try to fix that.
Expand Down Expand Up @@ -201,12 +187,15 @@ await WaitForSuccessAsync(new ProcessStartInfo

async Task PullRebase()
{
await WaitForSuccessAsync(GitNetCommand(new ProcessStartInfo
// GitCommitCommand() is needed because git asks for committer information when a rebase needs to happen.
// Why? Well quite frankly if git was well-coded I wouldn't have needed 5 attempts
// to figure out something like GitCommitCommand() that actually works, so...
await WaitForSuccessAsync(GitCommitCommand(GitNetCommand(new ProcessStartInfo
{
FileName = "git",
ArgumentList = {"pull", "--rebase"},
WorkingDirectory = repo
}), timeoutSeconds: 30);
})), timeoutSeconds: 30);
}

async Task Push()
Expand Down Expand Up @@ -242,6 +231,23 @@ await WaitForSuccessAsync(GitNetCommand(new ProcessStartInfo
WorkingDirectory = repo
}));
}

ProcessStartInfo GitCommitCommand(ProcessStartInfo info)
{
if (cfg.CommitAuthorName is { } authorName)
{
info.ArgumentList.Insert(0, "-c");
info.ArgumentList.Insert(1, "user.name=" + authorName);
}

if (cfg.CommitAuthorEmail is { } authorEmail)
{
info.ArgumentList.Insert(0, "-c");
info.ArgumentList.Insert(1, "user.email=" + authorEmail);
}

return info;
}
}

private ProcessStartInfo GitNetCommand(ProcessStartInfo info)
Expand Down

0 comments on commit 3d6971f

Please sign in to comment.