-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Enable Create PR for pushed branches that are ahead of main #2081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d441263
313f8d4
9af889b
fd242c0
b7f5f39
0f9418f
4cfe2b9
bce2d06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // @effect-diagnostics nodeBuiltinImport:off | ||
| import path from "node:path"; | ||
| import { spawnSync } from "node:child_process"; | ||
|
|
||
| export function preferRealGitOnPathForTests(): void { | ||
| process.env.GIT_CONFIG_GLOBAL = process.platform === "win32" ? "NUL" : "/dev/null"; | ||
| process.env.GIT_CONFIG_NOSYSTEM = "1"; | ||
|
|
||
| const result = spawnSync("git", ["ai", "git-path"], { encoding: "utf8" }); | ||
| if (result.status !== 0) { | ||
| return; | ||
| } | ||
|
|
||
| const gitPath = result.stdout.trim(); | ||
| if (gitPath.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| const gitDir = path.dirname(gitPath); | ||
| const pathEntries = (process.env.PATH ?? "") | ||
| .split(path.delimiter) | ||
| .filter((entry) => entry.length > 0 && entry !== gitDir); | ||
|
|
||
| process.env.PATH = [gitDir, ...pathEntries].join(path.delimiter); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,7 +103,7 @@ export function buildMenuItems( | |
| const hasChanges = gitStatus.hasWorkingTreeChanges; | ||
| const hasOpenPr = gitStatus.pr?.state === "open"; | ||
| const isBehind = gitStatus.behindCount > 0; | ||
| const hasDefaultBranchDelta = (gitStatus.aheadOfDefaultCount ?? gitStatus.aheadCount) > 0; | ||
| const isAheadOfBase = gitStatus.aheadOfBaseCount > 0; | ||
| const canPushWithoutUpstream = hasPrimaryRemote && !gitStatus.hasUpstream; | ||
| const canCommit = !isBusy && hasChanges; | ||
| const canPush = | ||
|
|
@@ -117,7 +117,7 @@ export function buildMenuItems( | |
| hasBranch && | ||
| !hasChanges && | ||
| !hasOpenPr && | ||
| hasDefaultBranchDelta && | ||
| isAheadOfBase && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing default branch guard in menu itemsLow Severity
Reviewed by Cursor Bugbot for commit bce2d06. Configure here. |
||
| !isBehind && | ||
| (gitStatus.hasUpstream || canPushWithoutUpstream); | ||
| const canOpenPr = !isBusy && hasOpenPr; | ||
|
|
@@ -187,7 +187,7 @@ export function resolveQuickAction( | |
| const hasChanges = gitStatus.hasWorkingTreeChanges; | ||
| const hasOpenPr = gitStatus.pr?.state === "open"; | ||
| const isAhead = gitStatus.aheadCount > 0; | ||
| const hasDefaultBranchDelta = (gitStatus.aheadOfDefaultCount ?? gitStatus.aheadCount) > 0; | ||
| const isAheadOfBase = gitStatus.aheadOfBaseCount > 0; | ||
| const isBehind = gitStatus.behindCount > 0; | ||
| const isDiverged = isAhead && isBehind; | ||
| const terminology = resolveChangeRequestTerminology(gitStatus); | ||
|
|
@@ -288,11 +288,7 @@ export function resolveQuickAction( | |
| }; | ||
| } | ||
|
|
||
| if (hasOpenPr && gitStatus.hasUpstream) { | ||
| return { label: `View ${terminology.shortLabel}`, disabled: false, kind: "open_pr" }; | ||
| } | ||
|
|
||
| if (hasDefaultBranchDelta && !isDefaultRef) { | ||
| if (isAheadOfBase && !hasOpenPr && !isDefaultRef) { | ||
| return { | ||
| label: `Create ${terminology.shortLabel}`, | ||
| disabled: false, | ||
|
|
@@ -301,6 +297,10 @@ export function resolveQuickAction( | |
| }; | ||
| } | ||
|
|
||
| if (hasOpenPr && gitStatus.hasUpstream) { | ||
| return { label: `View ${terminology.shortLabel}`, disabled: false, kind: "open_pr" }; | ||
| } | ||
|
|
||
| return { | ||
| label: "Commit", | ||
| disabled: true, | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate git process spawn for same computation
Medium Severity
computeAheadCountAgainstBase(cwd, refName)is called unconditionally at line 1250 to computeaheadOfBaseCount, but theaheadOfDefaultCountfallback at line 1270 calls the same function with the same arguments again whenfallbackAheadCount === null(i.e., when there IS an upstream). This spawns redundant git processes (resolveBaseBranchForNoUpstream+rev-list --count) on every status poll for non-default branches with an upstream — the exact scenario this PR targets. The value at line 1270 could simply reuseaheadOfBaseCount.Additional Locations (1)
apps/server/src/vcs/GitVcsDriverCore.ts#L1248-L1252Reviewed by Cursor Bugbot for commit bce2d06. Configure here.