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
43 changes: 43 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9720,6 +9720,49 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);

it.effect("publishes a new branch at the same commit as its local upstream", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const remote = yield* makeTmpDir("git-remote-");
const { initialBranch } = yield* initRepoWithCommit(cwd);
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* git(remote, ["init", "--bare"]);
yield* git(cwd, ["remote", "add", "origin", remote]);
yield* git(cwd, ["push", "-u", "origin", initialBranch]);
const remoteBase = yield* git(remote, [
"--git-dir=.",
"rev-parse",
`refs/heads/${initialBranch}`,
]);
yield* writeTextFile(cwd, "feature.txt", "feature\n");
yield* git(cwd, ["add", "feature.txt"]);
const { commitSha } = yield* driver.commit(cwd, "Add feature", "");
yield* git(cwd, ["config", "branch.autoSetupMerge", "always"]);
yield* driver.createRef({ cwd, refName: "feature/push" });
yield* driver.switchRef({ cwd, refName: "feature/push" });
assert.equal(
yield* git(cwd, ["rev-parse", "--symbolic-full-name", "@{upstream}"]),
`refs/heads/${initialBranch}`,
);

const pushed = yield* driver.pushCurrentBranch(cwd, null);

assert.deepInclude(pushed, {
status: "pushed",
upstreamBranch: "origin/feature/push",
setUpstream: true,
});
assert.equal(
yield* git(remote, ["--git-dir=.", "rev-parse", "refs/heads/feature/push"]),
commitSha,
);
assert.equal(
yield* git(remote, ["--git-dir=.", "rev-parse", `refs/heads/${initialBranch}`]),
remoteBase,
);
}),
);

it.effect("republishes a branch whose upstream was deleted", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
Expand Down
8 changes: 6 additions & 2 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3733,8 +3733,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const destination = yield* resolvePushDestination(cwd, branch, details.hasUpstream);
if (hasNoLocalDelta && details.hasUpstream) {
if (!destination?.pushRemote) {
// The tracking ref reflects the fetch URL, so it says nothing about a separate push URL.
if (!destination || (yield* pushesOnlyToFetchUrl(cwd, destination.remoteName))) {
// A local upstream and a separate push URL both leave the publish destination unchecked.
if (
!destination ||
(destination.upstream?.remoteName !== "." &&
(yield* pushesOnlyToFetchUrl(cwd, destination.remoteName)))
) {
return {
status: "skipped_up_to_date" as const,
branch,
Expand Down
17 changes: 17 additions & 0 deletions packages/client-runtime/src/state/gitActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ describe("git action copy", () => {
expect(resolveQuickAction({ ...pushed, isDefaultRef: true }, false, true).disabled).toBe(true);
});

it.each([
{ tracking: "with an upstream", hasUpstream: true },
{ tracking: "without an upstream", hasUpstream: false },
])("pushes existing commits from a clean default branch $tracking", ({ hasUpstream }) => {
const cleanDefaultBranch = status({
refName: "main",
isDefaultRef: true,
hasUpstream,
aheadCount: 1,
});
expect(resolveQuickAction(cleanDefaultBranch, false, true)).toMatchObject({
disabled: false,
kind: "run_action",
action: "push",
});
});

it("names the host's change request in the default-branch dialog", () => {
const input = { action: "commit_push_pr", branchName: "main", includesCommit: true } as const;
expect(
Expand Down
4 changes: 2 additions & 2 deletions packages/client-runtime/src/state/gitActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export function resolveQuickAction(
label: resolve(msg("Push", { $context: "verb, git action" })),
disabled: false,
kind: "run_action",
action: isDefaultBranch ? "commit_push" : "push",
action: "push",
};
}
return {
Expand Down Expand Up @@ -272,7 +272,7 @@ export function resolveQuickAction(
label: resolve(msg("Push", { $context: "verb, git action" })),
disabled: false,
kind: "run_action",
action: isDefaultBranch ? "commit_push" : "push",
action: "push",
};
}
return {
Expand Down
Loading