fix: address latest git action review feedback

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-03-01 19:50:05 -08:00
1 parent 075df4ef4f
commit 839feaf250
4 files changed
+76 -15

No files matched your search

@@ -1065,6 +1065,42 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
it.effect(
"pushes with upstream setup when comparable base exists but remote branch is missing",
() =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const remote = yield* makeTmpDir();
yield* git(remote, ["init", "--bare"]);
yield* initRepoWithCommit(tmp);
const initialBranch = (yield* listGitBranches({ cwd: tmp })).branches.find(
(branch) => branch.current,
)!.name;
yield* git(tmp, ["remote", "add", "origin", remote]);
yield* git(tmp, ["push", "-u", "origin", initialBranch]);
yield* writeTextFile(path.join(tmp, "default-ahead.txt"), "ahead on default\n");
yield* git(tmp, ["add", "default-ahead.txt"]);
yield* git(tmp, ["commit", "-m", "default ahead"]);
const featureBranch = "feature/publish-no-upstream";
yield* git(tmp, ["checkout", "-b", featureBranch]);
const core = yield* GitCore;
const pushed = yield* core.pushCurrentBranch(tmp, null);
expect(pushed.status).toBe("pushed");
expect(pushed.setUpstream).toBe(true);
expect(pushed.upstreamBranch).toBe(`origin/${featureBranch}`);
expect(yield* git(tmp, ["rev-parse", "--abbrev-ref", "@{upstream}"])).toBe(
`origin/${featureBranch}`,
);
expect(yield* git(tmp, ["ls-remote", "--heads", "origin", featureBranch])).toContain(
featureBranch,
);
}),
);
it.effect("includes command context when worktree removal fails", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
+24 -4
View File
@@ -300,6 +300,11 @@ const makeGitCore = Effect.gen(function* () {
},
).pipe(Effect.map((result) => result.code === 0));
const originRemoteExists = (cwd: string): Effect.Effect<boolean, GitCommandError> =>
executeGit("GitCore.originRemoteExists", cwd, ["remote", "get-url", "origin"], {
allowNonZeroExit: true,
}).pipe(Effect.map((result) => result.code === 0));
const resolveBaseBranchForNoUpstream = (
cwd: string,
branch: string,
@@ -582,10 +587,25 @@ const makeGitCore = Effect.gen(function* () {
Effect.catch(() => Effect.succeed(null)),
);
if (comparableBaseBranch) {
return {
status: "skipped_up_to_date" as const,
branch,
};
const hasOriginRemote = yield* originRemoteExists(cwd).pipe(
Effect.catch(() => Effect.succeed(false)),
);
if (!hasOriginRemote) {
return {
status: "skipped_up_to_date" as const,
branch,
};
}
const hasRemoteBranch = yield* remoteBranchExists(cwd, branch).pipe(
Effect.catch(() => Effect.succeed(false)),
);
if (hasRemoteBranch) {
return {
status: "skipped_up_to_date" as const,
branch,
};
}
}
}
@@ -31,6 +31,8 @@ export interface DefaultBranchActionDialogCopy {
continueLabel: string;
}
export type DefaultBranchConfirmableAction = "commit_push" | "commit_push_pr";
const SHORT_SHA_LENGTH = 7;
const TOAST_DESCRIPTION_MAX = 72;
const AUTO_FEATURE_BRANCH_PREFIX = "feature/stacked";
@@ -283,21 +285,13 @@ export function requiresDefaultBranchConfirmation(
}
export function resolveDefaultBranchActionDialogCopy(input: {
action: GitStackedAction;
action: DefaultBranchConfirmableAction;
branchName: string;
includesCommit: boolean;
}): DefaultBranchActionDialogCopy {
const branchLabel = input.branchName;
const suffix = ` on "${branchLabel}". You can continue on this branch or create a feature branch and run the same action there.`;
if (input.action === "commit") {
return {
title: "Commit to default branch?",
description: `This action will commit changes${suffix}`,
continueLabel: `Commit to ${branchLabel}`,
};
}
if (input.action === "commit_push") {
if (input.includesCommit) {
return {
+13 -2
View File
@@ -9,6 +9,7 @@ import {
type GitActionIconName,
type GitActionMenuItem,
type GitQuickAction,
type DefaultBranchConfirmableAction,
requiresDefaultBranchConfirmation,
resolveAutoFeatureBranchName,
resolveDefaultBranchActionDialogCopy,
@@ -50,7 +51,7 @@ interface GitActionsControlProps {
}
interface PendingDefaultBranchAction {
action: GitStackedAction;
action: DefaultBranchConfirmableAction;
branchName: string;
includesCommit: boolean;
commitMessage?: string;
@@ -268,6 +269,9 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
requiresDefaultBranchConfirmation(action, actionIsDefaultBranch) &&
actionBranch
) {
if (action !== "commit_push" && action !== "commit_push_pr") {
return;
}
setPendingDefaultBranchAction({
action,
branchName: actionBranch,
@@ -578,11 +582,18 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
if (!isCommitDialogOpen) return;
const commitMessage = dialogCommitMessage.trim();
setIsCommitDialogOpen(false);
setDialogCommitMessage("");
void runGitActionWithToast({
action: "commit",
...(commitMessage ? { commitMessage } : {}),
});
}, [dialogCommitMessage, isCommitDialogOpen, runGitActionWithToast, setIsCommitDialogOpen]);
}, [
dialogCommitMessage,
isCommitDialogOpen,
runGitActionWithToast,
setDialogCommitMessage,
setIsCommitDialogOpen,
]);
const openChangedFileInEditor = useCallback(
(filePath: string) => {