@@ -64,6 +64,9 @@ describe('gitContext', () => {
6464 prHeadRef : boolean ;
6565 sendGitQueryAsInput : boolean ;
6666 buildxQuerySupport : boolean ;
67+ subdir ?: string ;
68+ keepGitDir ?: boolean ;
69+ submodules ?: boolean ;
6770 } ;
6871
6972 // prettier-ignore
@@ -79,28 +82,47 @@ describe('gitContext', () => {
7982 [ { ref : 'refs/pull/15/merge' , format : undefined , prHeadRef : false , sendGitQueryAsInput : true , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/merge&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
8083 [ { ref : 'refs/pull/15/merge' , format : undefined , prHeadRef : true , sendGitQueryAsInput : true , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/head&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
8184 [ { ref : 'refs/heads/master' , format : undefined , prHeadRef : false , sendGitQueryAsInput : true , buildxQuerySupport : false } , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
85+ [ { ref : 'refs/heads/master' , format : undefined , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true , keepGitDir : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&keep-git-dir=1' ] ,
86+ [ { ref : 'refs/heads/master' , format : undefined , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : false , keepGitDir : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&keep-git-dir=1' ] ,
87+ [ { ref : 'refs/heads/master' , format : undefined , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true , submodules : false } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&submodules=false' ] ,
88+ [ { ref : 'refs/heads/master' , format : undefined , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : false , submodules : false } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&submodules=false' ] ,
8289 // query format
8390 [ { ref : 'refs/heads/master' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
8491 [ { ref : 'master' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
8592 [ { ref : 'refs/pull/15/merge' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/merge&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
8693 [ { ref : 'refs/tags/v1.0.0' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/tags/v1.0.0&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
8794 [ { ref : 'refs/pull/15/merge' , format : 'query' , prHeadRef : true , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/head&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
95+ [ { ref : 'refs/heads/master' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true , subdir : 'subdir' } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&subdir=subdir' ] ,
96+ [ { ref : 'refs/heads/master' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true , subdir : 'subdir' , keepGitDir : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&subdir=subdir&keep-git-dir=1' ] ,
97+ [ { ref : 'refs/heads/master' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true , submodules : true } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&submodules=true' ] ,
98+ [ { ref : 'refs/heads/master' , format : 'query' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true , submodules : false } , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37&submodules=false' ] ,
8899 // fragment format
89100 [ { ref : 'refs/heads/master' , format : 'fragment' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
90101 [ { ref : 'master' , format : 'fragment' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
91102 [ { ref : 'refs/pull/15/merge' , format : 'fragment' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git#refs/pull/15/merge' ] ,
92103 [ { ref : 'refs/tags/v1.0.0' , format : 'fragment' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
93104 [ { ref : 'refs/pull/15/merge' , format : 'fragment' , prHeadRef : true , sendGitQueryAsInput : false , buildxQuerySupport : true } , 'https://github.com/docker/actions-toolkit.git#refs/pull/15/head' ] ,
105+ [ { ref : 'refs/heads/master' , format : 'fragment' , prHeadRef : false , sendGitQueryAsInput : false , buildxQuerySupport : true , subdir : 'subdir' } , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37:subdir' ] ,
106+ [ { ref : 'refs/pull/15/merge' , format : 'fragment' , prHeadRef : true , sendGitQueryAsInput : false , buildxQuerySupport : true , subdir : 'subdir' } , 'https://github.com/docker/actions-toolkit.git#refs/pull/15/head:subdir' ] ,
94107 ] ;
95108
96109 test . each ( gitContextCases ) ( 'given %o should return %o' , async ( input : GitContextTestCase , expected : string ) => {
97- const { ref, format, prHeadRef, sendGitQueryAsInput, buildxQuerySupport} = input ;
110+ const { ref, format, prHeadRef, sendGitQueryAsInput, buildxQuerySupport, subdir , keepGitDir , submodules } = input ;
98111 process . env . DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF = prHeadRef ? 'true' : '' ;
99112 process . env . BUILDX_SEND_GIT_QUERY_AS_INPUT = sendGitQueryAsInput ? 'true' : '' ;
100113 const buildx = new Buildx ( ) ;
101114 vi . spyOn ( buildx , 'versionSatisfies' ) . mockResolvedValue ( buildxQuerySupport ) ;
102115 const build = new Build ( { buildx} ) ;
103- expect ( await build . gitContext ( ref , '860c1904a1ce19322e91ac35af1ab07466440c37' , format ) ) . toEqual ( expected ) ;
116+ expect (
117+ await build . gitContext ( {
118+ ref,
119+ checksum : '860c1904a1ce19322e91ac35af1ab07466440c37' ,
120+ format,
121+ subdir,
122+ keepGitDir,
123+ submodules
124+ } )
125+ ) . toEqual ( expected ) ;
104126 } ) ;
105127} ) ;
106128
0 commit comments