77import * as pathLib from 'path' ;
88import * as vscode from 'vscode' ;
99import { Repository } from './api/api' ;
10- import { GitErrorCodes , Status } from './api/api1' ;
10+ import { GitErrorCodes } from './api/api1' ;
1111import { CommentReply , findActiveHandler , resolveCommentHandler } from './commentHandlerResolver' ;
1212import { commands } from './common/executeCommands' ;
1313import Logger from './common/logger' ;
14- import * as PersistentState from './common/persistentState' ;
1514import { FILE_LIST_LAYOUT , HIDE_VIEWED_FILES , PR_SETTINGS_NAMESPACE } from './common/settingKeys' ;
1615import { editQuery } from './common/settingsUtils' ;
1716import { ITelemetry } from './common/telemetry' ;
@@ -51,81 +50,6 @@ import {
5150import { PRNode } from './view/treeNodes/pullRequestNode' ;
5251import { RepositoryChangesNode } from './view/treeNodes/repositoryChangesNode' ;
5352
54- // Modal dialog options for handling uncommitted changes during PR checkout
55- const STASH_CHANGES = vscode . l10n . t ( 'Stash changes' ) ;
56- const DISCARD_CHANGES = vscode . l10n . t ( 'Discard changes' ) ;
57- const DONT_SHOW_AGAIN = vscode . l10n . t ( 'Try to checkout anyway and don\'t show again' ) ;
58-
59- // Constants for persistent state storage
60- const UNCOMMITTED_CHANGES_SCOPE = vscode . l10n . t ( 'uncommitted changes warning' ) ;
61- const UNCOMMITTED_CHANGES_STORAGE_KEY = 'showWarning' ;
62-
63- /**
64- * Shows a modal dialog when there are uncommitted changes during PR checkout
65- * @param repository The git repository with uncommitted changes
66- * @returns Promise<boolean> true if user chose to proceed (after staging/discarding), false if cancelled
67- */
68- async function handleUncommittedChanges ( repository : Repository ) : Promise < boolean > {
69- // Check if user has disabled the warning using persistent state
70- if ( PersistentState . fetch ( UNCOMMITTED_CHANGES_SCOPE , UNCOMMITTED_CHANGES_STORAGE_KEY ) === false ) {
71- return true ; // User has disabled warnings, proceed without showing dialog
72- }
73-
74- // Filter out untracked files as they typically don't conflict with PR checkout
75- const trackedWorkingTreeChanges = repository . state . workingTreeChanges . filter ( change => change . status !== Status . UNTRACKED ) ;
76- const hasTrackedWorkingTreeChanges = trackedWorkingTreeChanges . length > 0 ;
77- const hasIndexChanges = repository . state . indexChanges . length > 0 ;
78-
79- if ( ! hasTrackedWorkingTreeChanges && ! hasIndexChanges ) {
80- return true ; // No tracked uncommitted changes, proceed
81- }
82-
83- const modalResult = await vscode . window . showInformationMessage (
84- vscode . l10n . t ( 'You have uncommitted changes that might be overwritten by checking out this pull request.' ) ,
85- {
86- modal : true ,
87- detail : vscode . l10n . t ( 'Choose how to handle your uncommitted changes before checking out the pull request.' ) ,
88- } ,
89- STASH_CHANGES ,
90- DISCARD_CHANGES ,
91- DONT_SHOW_AGAIN ,
92- ) ;
93-
94- if ( ! modalResult ) {
95- return false ; // User cancelled
96- }
97-
98- if ( modalResult === DONT_SHOW_AGAIN ) {
99- // Store preference to never show this dialog again using persistent state
100- PersistentState . store ( UNCOMMITTED_CHANGES_SCOPE , UNCOMMITTED_CHANGES_STORAGE_KEY , false ) ;
101- return true ; // Proceed with checkout
102- }
103-
104- try {
105- if ( modalResult === STASH_CHANGES ) {
106- // Stash all changes (working tree changes + any unstaged changes)
107- const allChangedFiles = [
108- ...trackedWorkingTreeChanges . map ( change => change . uri . fsPath ) ,
109- ...repository . state . indexChanges . map ( change => change . uri . fsPath ) ,
110- ] ;
111- if ( allChangedFiles . length > 0 ) {
112- await repository . add ( allChangedFiles ) ;
113- await vscode . commands . executeCommand ( 'git.stash' , repository ) ;
114- }
115- } else if ( modalResult === DISCARD_CHANGES ) {
116- // Discard all tracked working tree changes
117- const trackedWorkingTreeFiles = trackedWorkingTreeChanges . map ( change => change . uri . fsPath ) ;
118- if ( trackedWorkingTreeFiles . length > 0 ) {
119- await repository . clean ( trackedWorkingTreeFiles ) ;
120- }
121- }
122- return true ; // Successfully handled changes, proceed with checkout
123- } catch ( error ) {
124- vscode . window . showErrorMessage ( vscode . l10n . t ( 'Failed to handle uncommitted changes: {0}' , formatError ( error ) ) ) ;
125- return false ;
126- }
127- }
128-
12953function ensurePR ( folderRepoManager : FolderRepositoryManager , pr ?: PRNode ) : PullRequestModel ;
13054function ensurePR < TIssue extends Issue , TIssueModel extends IssueModel < TIssue > > ( folderRepoManager : FolderRepositoryManager , pr ?: TIssueModel ) : TIssueModel ;
13155function ensurePR < TIssue extends Issue , TIssueModel extends IssueModel < TIssue > > ( folderRepoManager : FolderRepositoryManager , pr ?: PRNode | TIssueModel ) : TIssueModel {
@@ -493,37 +417,6 @@ export function registerCommands(
493417 ) ,
494418 ) ;
495419
496- const switchToPr = async ( folderManager : FolderRepositoryManager , pullRequestModel : PullRequestModel , repository : Repository | undefined , isFromDescription : boolean ) => {
497- // If we don't have a repository from the node, use the one from the folder manager
498- const repositoryToCheck = repository || folderManager . repository ;
499-
500- // Check for uncommitted changes before proceeding with checkout
501- const shouldProceed = await handleUncommittedChanges ( repositoryToCheck ) ;
502- if ( ! shouldProceed ) {
503- return ; // User cancelled or there was an error handling changes
504- }
505-
506- /* __GDPR__
507- "pr.checkout" : {
508- "fromDescriptionPage" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
509- }
510- */
511- telemetry . sendTelemetryEvent ( 'pr.checkout' , { fromDescription : isFromDescription . toString ( ) } ) ;
512-
513- return vscode . window . withProgress (
514- {
515- location : vscode . ProgressLocation . SourceControl ,
516- title : vscode . l10n . t ( 'Switching to Pull Request #{0}' , pullRequestModel . number ) ,
517- } ,
518- async ( ) => {
519- await ReviewManager . getReviewManagerForRepository (
520- reviewsManager . reviewManagers ,
521- pullRequestModel . githubRepository ,
522- repository
523- ) ?. switch ( pullRequestModel ) ;
524- } ) ;
525- } ;
526-
527420 context . subscriptions . push (
528421 vscode . commands . registerCommand ( 'pr.pick' , async ( pr : PRNode | RepositoryChangesNode | PullRequestModel ) => {
529422 if ( pr === undefined ) {
@@ -549,7 +442,7 @@ export function registerCommands(
549442 }
550443
551444 const fromDescriptionPage = pr instanceof PullRequestModel ;
552- return switchToPr ( folderManager , pullRequestModel , repository , fromDescriptionPage ) ;
445+ return reviewsManager . switchToPr ( folderManager , pullRequestModel , repository , fromDescriptionPage ) ;
553446
554447 } ) ) ;
555448
@@ -653,14 +546,14 @@ export function registerCommands(
653546 return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find pull request #{0}' , prNumber . toString ( ) ) ) ;
654547 }
655548
656- return switchToPr ( folderManager , pullRequest , folderManager . repository , true ) ;
549+ return reviewsManager . switchToPr ( folderManager , pullRequest , folderManager . repository , true ) ;
657550 }
658551
659552 const resolved = await resolvePr ( ctx ) ;
660553 if ( ! resolved ) {
661554 return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to resolve pull request for checkout.' ) ) ;
662555 }
663- return switchToPr ( resolved . folderManager , resolved . pr , resolved . folderManager . repository , true ) ;
556+ return reviewsManager . switchToPr ( resolved . folderManager , resolved . pr , resolved . folderManager . repository , true ) ;
664557
665558 } ) ) ;
666559
@@ -1035,7 +928,7 @@ export function registerCommands(
1035928 return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find repository for pull request #{0}' , pr . number . toString ( ) ) ) ;
1036929 }
1037930
1038- return switchToPr ( folderManager , pr , folderManager . repository , false ) ;
931+ return reviewsManager . switchToPr ( folderManager , pr , folderManager . repository , false ) ;
1039932 }
1040933
1041934 async function closeChatSessionPullRequest ( argument : ChatSessionWithPR | CrossChatSessionWithPR ) {
0 commit comments