Skip to content

Commit f399125

Browse files
committed
Fix pull-platformplatform-changes failing when local main is behind origin
1 parent c2920cb commit f399125

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

developer-cli/Commands/PullPlatformPlatformChangesCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private static void EnsureValidGitState()
106106

107107
GitHelper.EnsureUpstreamRemoteExists(PlatformplatformGitPath);
108108
GitHelper.EnsureBranchIsUpToDate();
109+
GitHelper.EnsureLocalBranchInSyncWithOrigin(TrunkBranchName);
109110
}
110111

111112
private static Commit[] GetNewCommitsFromPlatformPlatform()
@@ -398,7 +399,7 @@ private static void PreparePullRequest(Commit[] pullrequestCommits)
398399
);
399400

400401
var pullRequestDescription = body.ToString();
401-
AnsiConsole.MarkupLine(pullRequestDescription);
402+
AnsiConsole.MarkupLine(pullRequestDescription.EscapeMarkup());
402403
AnsiConsole.Confirm("Copy the above text as a description and use it for the pull request description. Continue?");
403404

404405
GitHelper.PushBranch(PullRequestBranchName);

developer-cli/Utilities/GitHelper.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ public static void PushBranch(string branchName)
218218
}
219219
}
220220

221+
public static void EnsureLocalBranchInSyncWithOrigin(string branchName)
222+
{
223+
var localHash = ProcessHelper.StartProcess($"git rev-parse {branchName}", Configuration.SourceCodeFolder, true).Trim();
224+
var originHash = ProcessHelper.StartProcess($"git rev-parse {DefaultRemote}/{branchName}", Configuration.SourceCodeFolder, true).Trim();
225+
226+
if (localHash != originHash)
227+
{
228+
AnsiConsole.MarkupLine($"[red]Your local '{branchName}' branch is not in sync with '{DefaultRemote}/{branchName}'. Please pull or push changes before running this command.[/]");
229+
Environment.Exit(1);
230+
}
231+
}
232+
221233
public static int GetPullRequestNumber(Commit commit, string pattern)
222234
{
223235
var match = Regex.Match(commit.Message, pattern);

0 commit comments

Comments
 (0)