@@ -47,6 +47,7 @@ import type { GKCheckInResponse } from '../checkin';
4747import { getSubscriptionFromCheckIn } from '../checkin' ;
4848import type { ServerConnection } from '../serverConnection' ;
4949import { ensurePlusFeaturesEnabled } from '../utils' ;
50+ import { AuthenticationContext } from './authenticationConnection' ;
5051import { authenticationProviderId , authenticationProviderScopes } from './authenticationProvider' ;
5152import type { Organization } from './organization' ;
5253import type { Subscription } from './subscription' ;
@@ -361,7 +362,31 @@ export class SubscriptionService implements Disposable {
361362 ) ;
362363 }
363364
364- return this . loginCore ( { signUp : signUp , source : source } ) ;
365+ let context : AuthenticationContext | undefined ;
366+ switch ( source ?. source ) {
367+ case 'graph' :
368+ context = AuthenticationContext . Graph ;
369+ break ;
370+ case 'timeline' :
371+ context = AuthenticationContext . VisualFileHistory ;
372+ break ;
373+ case 'git-commands' :
374+ if (
375+ source . detail != null &&
376+ typeof source . detail !== 'string' &&
377+ ( source . detail [ 'action' ] === 'worktree' ||
378+ source . detail [ 'step.title' ] === 'Create Worktree' ||
379+ source . detail [ 'step.title' ] === 'Open Worktree' )
380+ ) {
381+ context = AuthenticationContext . Worktrees ;
382+ }
383+ break ;
384+ case 'worktrees' :
385+ context = AuthenticationContext . Worktrees ;
386+ break ;
387+ }
388+
389+ return this . loginCore ( { signUp : signUp , source : source , context : context } ) ;
365390 }
366391
367392 async loginWithCode ( authentication : { code : string ; state ?: string } , source ?: Source ) : Promise < boolean > {
@@ -382,6 +407,7 @@ export class SubscriptionService implements Disposable {
382407 signUp ?: boolean ;
383408 source ?: Source ;
384409 signIn ?: { code : string ; state ?: string } ;
410+ context ?: AuthenticationContext ;
385411 } ) : Promise < boolean > {
386412 // Abort any waiting authentication to ensure we can start a new flow
387413 await this . container . accountAuthentication . abort ( ) ;
@@ -390,6 +416,7 @@ export class SubscriptionService implements Disposable {
390416 const session = await this . ensureSession ( true , {
391417 signIn : options ?. signIn ,
392418 signUp : options ?. signUp ,
419+ context : options ?. context ,
393420 } ) ;
394421 const loggedIn = Boolean ( session ) ;
395422 if ( loggedIn ) {
@@ -941,7 +968,12 @@ export class SubscriptionService implements Disposable {
941968 @debug ( )
942969 private async ensureSession (
943970 createIfNeeded : boolean ,
944- options ?: { force ?: boolean ; signUp ?: boolean ; signIn ?: { code : string ; state ?: string } } ,
971+ options ?: {
972+ force ?: boolean ;
973+ signUp ?: boolean ;
974+ signIn ?: { code : string ; state ?: string } ;
975+ context ?: AuthenticationContext ;
976+ } ,
945977 ) : Promise < AuthenticationSession | undefined > {
946978 if ( this . _sessionPromise != null ) {
947979 void ( await this . _sessionPromise ) ;
@@ -954,6 +986,7 @@ export class SubscriptionService implements Disposable {
954986 this . _sessionPromise = this . getOrCreateSession ( createIfNeeded , {
955987 signUp : options ?. signUp ,
956988 signIn : options ?. signIn ,
989+ context : options ?. context ,
957990 } ) . then (
958991 s => {
959992 this . _session = s ;
@@ -975,7 +1008,7 @@ export class SubscriptionService implements Disposable {
9751008 @debug ( )
9761009 private async getOrCreateSession (
9771010 createIfNeeded : boolean ,
978- options ?: { signUp ?: boolean ; signIn ?: { code : string ; state ?: string } } ,
1011+ options ?: { signUp ?: boolean ; signIn ?: { code : string ; state ?: string } ; context ?: AuthenticationContext } ,
9791012 ) : Promise < AuthenticationSession | null > {
9801013 const scope = getLogScope ( ) ;
9811014
0 commit comments