@@ -50,7 +50,7 @@ import {
5050 isTagReference ,
5151} from '../git/utils/reference.utils' ;
5252import { getHighlanderProviderName } from '../git/utils/remote.utils' ;
53- import { createRevisionRange , isRevisionRange } from '../git/utils/revision.utils' ;
53+ import { createRevisionRange , getRevisionRangeParts , isRevisionRange , isSha } from '../git/utils/revision.utils' ;
5454import { getSubscriptionNextPaidPlanId , isSubscriptionPaidPlan } from '../plus/gk/utils/subscription.utils' ;
5555import type { LaunchpadCommandArgs } from '../plus/launchpad/launchpad' ;
5656import {
@@ -493,27 +493,51 @@ export async function getBranchesAndOrTags(
493493
494494export function getValidateGitReferenceFn (
495495 repos : Repository | Repository [ ] | undefined ,
496- options ?: { buttons ?: QuickInputButton [ ] ; ranges ?: boolean } ,
496+ options ?: {
497+ revs ?: { allow : boolean ; buttons ?: QuickInputButton [ ] } ;
498+ ranges ?: { allow : boolean ; buttons ?: QuickInputButton [ ] ; validate ?: boolean } ;
499+ } ,
497500) {
498501 return async ( quickpick : QuickPick < any > , value : string ) : Promise < boolean > => {
499- let inRefMode = false ;
500- if ( value . startsWith ( '#' ) ) {
501- inRefMode = true ;
502- value = value . substring ( 1 ) ;
503- }
504-
505502 if ( repos == null ) return false ;
506503 if ( Array . isArray ( repos ) ) {
507504 if ( repos . length !== 1 ) return false ;
508505
509506 repos = repos [ 0 ] ;
510507 }
511508
512- if ( inRefMode && options ?. ranges && isRevisionRange ( value ) ) {
509+ let allowRevs = false ;
510+ if ( value . startsWith ( '#' ) ) {
511+ allowRevs = options ?. revs ?. allow ?? true ;
512+ value = value . substring ( 1 ) ;
513+ allowRevs = true ;
514+ } else if ( isSha ( value ) ) {
515+ allowRevs = options ?. revs ?. allow ?? true ;
516+ }
517+
518+ if ( options ?. ranges ?. allow && isRevisionRange ( value ) ) {
519+ if ( options ?. ranges ?. validate ) {
520+ // Validate the parts of the range
521+ const parts = getRevisionRangeParts ( value ) ;
522+ const [ leftResult , rightResult ] = await Promise . allSettled ( [
523+ parts ?. left != null ? repos . git . refs . isValidReference ( parts . left ) : Promise . resolve ( true ) ,
524+ parts ?. right != null ? repos . git . refs . isValidReference ( parts . right ) : Promise . resolve ( true ) ,
525+ ] ) ;
526+
527+ if ( ! getSettledValue ( leftResult , false ) || ! getSettledValue ( rightResult , false ) ) {
528+ quickpick . items = [
529+ createDirectiveQuickPickItem ( Directive . Noop , true , {
530+ label : `Invalid Range: ${ value } ` ,
531+ } ) ,
532+ ] ;
533+ return true ;
534+ }
535+ }
536+
513537 quickpick . items = [
514538 createRefQuickPickItem ( value , repos . path , true , {
515539 alwaysShow : true ,
516- buttons : options ?. buttons ,
540+ buttons : options ?. ranges ?. buttons ,
517541 ref : false ,
518542 icon : false ,
519543 } ) ,
@@ -522,9 +546,9 @@ export function getValidateGitReferenceFn(
522546 }
523547
524548 if ( ! ( await repos . git . refs . isValidReference ( value ) ) ) {
525- if ( inRefMode ) {
549+ if ( allowRevs ) {
526550 quickpick . items = [
527- createDirectiveQuickPickItem ( Directive . Back , true , {
551+ createDirectiveQuickPickItem ( Directive . Noop , true , {
528552 label : 'Enter a reference or commit SHA' ,
529553 } ) ,
530554 ] ;
@@ -534,7 +558,7 @@ export function getValidateGitReferenceFn(
534558 return false ;
535559 }
536560
537- if ( ! inRefMode ) {
561+ if ( ! allowRevs ) {
538562 if (
539563 await repos . git . refs . hasBranchOrTag ( {
540564 filter : { branches : b => b . name . includes ( value ) , tags : t => t . name . includes ( value ) } ,
@@ -548,7 +572,7 @@ export function getValidateGitReferenceFn(
548572 quickpick . items = [
549573 await createCommitQuickPickItem ( commit ! , true , {
550574 alwaysShow : true ,
551- buttons : options ?. buttons ,
575+ buttons : options ?. revs ?. buttons ,
552576 compact : true ,
553577 icon : 'avatar' ,
554578 } ) ,
@@ -1028,7 +1052,10 @@ export function* pickBranchOrTagStep<
10281052 void showCommitInDetailsView ( item , { pin : false , preserveFocus : true } ) ;
10291053 }
10301054 } ,
1031- onValidateValue : getValidateGitReferenceFn ( state . repo , { ranges : ranges } ) ,
1055+ onValidateValue : getValidateGitReferenceFn (
1056+ state . repo ,
1057+ ranges ? { ranges : { allow : true , validate : true } } : undefined ,
1058+ ) ,
10321059 } ) ;
10331060
10341061 const selection : StepSelection < typeof step > = yield step ;
@@ -1307,7 +1334,7 @@ export async function* pickCommitStep<
13071334 }
13081335 } ,
13091336 onValidateValue : getValidateGitReferenceFn ( state . repo , {
1310- buttons : [ ShowDetailsViewQuickInputButton , RevealInSideBarQuickInputButton ] ,
1337+ revs : { allow : true , buttons : [ ShowDetailsViewQuickInputButton , RevealInSideBarQuickInputButton ] } ,
13111338 } ) ,
13121339 } ) ;
13131340
0 commit comments