Skip to content

Commit 9420247

Browse files
Copilotalexr00
andcommitted
Address code review feedback
- Fix redundant check for empty files - Don't re-add already staged index changes - Fix race condition by reading stash flag after checkout Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 30a8977 commit 9420247

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/github/activityBarViewProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
131131
try {
132132
const defaultBranch = await this._folderRepositoryManager.getPullRequestRepositoryDefaultBranch(this._item);
133133
const prBranch = this._folderRepositoryManager.repository.state.HEAD?.name;
134-
const shouldPopStash = this._folderRepositoryManager.stashedOnCheckout;
135134
await this._folderRepositoryManager.checkoutDefaultBranch(defaultBranch);
135+
// Check if we should pop the stash after successful checkout
136+
const shouldPopStash = this._folderRepositoryManager.stashedOnCheckout;
136137
if (shouldPopStash) {
137138
try {
138139
Logger.appendLine('Popping stash after returning to default branch', 'ActivityBarViewProvider');

src/github/pullRequestOverview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,9 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
652652
private async checkoutDefaultBranch(message: IRequestMessage<string>): Promise<void> {
653653
try {
654654
const prBranch = this._folderRepositoryManager.repository.state.HEAD?.name;
655-
const shouldPopStash = this._folderRepositoryManager.stashedOnCheckout;
656655
await this._folderRepositoryManager.checkoutDefaultBranch(message.args);
656+
// Check if we should pop the stash after successful checkout
657+
const shouldPopStash = this._folderRepositoryManager.stashedOnCheckout;
657658
if (shouldPopStash) {
658659
try {
659660
Logger.appendLine('Popping stash after returning to default branch', PullRequestOverviewPanel.ID);

src/view/reviewManager.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,10 @@ export class ReviewManager extends Disposable {
11001100
if (hasChanges) {
11011101
try {
11021102
Logger.appendLine('Auto-stashing changes before PR checkout', this.id);
1103-
// Add all tracked changes to staging area
1104-
const allChangedFiles = [
1105-
...workingTreeChanges.map(change => change.uri.fsPath),
1106-
...indexChanges.map(change => change.uri.fsPath),
1107-
];
1108-
if (allChangedFiles.length > 0) {
1109-
await this._repository.add(allChangedFiles);
1103+
// Add only working tree changes to staging area (indexChanges are already staged)
1104+
if (workingTreeChanges.length > 0) {
1105+
const workingTreeFiles = workingTreeChanges.map(change => change.uri.fsPath);
1106+
await this._repository.add(workingTreeFiles);
11101107
}
11111108
// Stash the changes
11121109
await vscode.commands.executeCommand('git.stash', this._repository);

0 commit comments

Comments
 (0)