Disable pull and push until the branch diverges

This commit is contained in:
Mohamed Boudra
2026-06-07 14:21:32 +07:00
parent e1b27fc584
commit 69715a77e9
2 changed files with 38 additions and 0 deletions

View File

@@ -252,6 +252,38 @@ describe("git-actions-policy", () => {
});
});
it("keeps pull-and-push unavailable when the branch only has outgoing commits", () => {
const actions = buildGitActions(
createInput({
hasRemote: true,
aheadOfOrigin: 2,
behindOfOrigin: 0,
}),
);
const action = actions.secondary.find((entry) => entry.id === "pull-and-push");
expect(action).toMatchObject({
label: "Pull and push",
unavailableMessage: expect.any(String),
});
});
it("keeps pull-and-push unavailable when the branch only has incoming commits", () => {
const actions = buildGitActions(
createInput({
hasRemote: true,
aheadOfOrigin: 0,
behindOfOrigin: 2,
}),
);
const action = actions.secondary.find((entry) => entry.id === "pull-and-push");
expect(action).toMatchObject({
label: "Pull and push",
unavailableMessage: expect.any(String),
});
});
it("explains why pull-and-push is unavailable when the branch is in sync", () => {
const actions = buildGitActions(createInput({ hasRemote: true }));
const action = actions.secondary.find((entry) => entry.id === "pull-and-push");

View File

@@ -616,6 +616,12 @@ function getPullAndPushUnavailableMessage(input: BuildGitActionsInput): string |
if (input.behindOfOrigin === 0 && input.aheadOfOrigin === 0) {
return "Pull and push isn't available because this branch is already in sync";
}
if (input.behindOfOrigin === 0) {
return "Pull and push isn't available because there are no incoming changes to pull first";
}
if (input.aheadOfOrigin === 0) {
return "Pull and push isn't available because there is nothing new to send after pulling";
}
return undefined;
}