@@ -4,6 +4,9 @@ import { useTranslation } from 'react-i18next';
4
4
import { parseDevfile } from '@console/internal/module/k8s' ;
5
5
import { DevfileSuggestedResources } from '../import-types' ;
6
6
7
+ const suffixSlash = ( val : string ) => ( val . endsWith ( '/' ) ? val : `${ val } /` ) ;
8
+ const prefixDotSlash = ( val ) => ( val . startsWith ( '/' ) ? val : `.${ val } ` ) ;
9
+
7
10
export const useDefileServer = (
8
11
values : FormikValues ,
9
12
setFieldValue : ( name : string , value : any ) => any ,
@@ -26,7 +29,7 @@ export const useDefileServer = (
26
29
27
30
return {
28
31
name,
29
- git : { URL : url , ref, dir } ,
32
+ git : { URL : url , ref, dir : prefixDotSlash ( dir ) } ,
30
33
devfile : { devfileContent, devfilePath } ,
31
34
} ;
32
35
} , [ name , url , ref , dir , devfileContent , devfilePath ] ) ;
@@ -86,8 +89,7 @@ export const useDevfileDirectoryWatcher = (
86
89
git : { dir } ,
87
90
} = values ;
88
91
React . useEffect ( ( ) => {
89
- let smartSlashDir = dir . endsWith ( '/' ) ? dir : `${ dir } /` ;
90
- smartSlashDir = smartSlashDir . startsWith ( '.' ) ? smartSlashDir : `.${ smartSlashDir } ` ;
92
+ const smartSlashDir = prefixDotSlash ( suffixSlash ( dir ) ) ;
91
93
92
94
setFieldValue ( 'devfile.devfilePath' , `${ smartSlashDir } devfile.yaml` ) ;
93
95
setFieldValue ( 'docker.dockerfilePath' , `${ smartSlashDir } Dockerfile` ) ;
0 commit comments