@@ -23,6 +23,8 @@ import * as rimraf from 'rimraf';
2323import  { Context }  from  '../../src/context' ; 
2424import  { Build }  from  '../../src/buildx/build' ; 
2525
26+ import  { GitContextFormat }  from  '../../src/types/buildx/build' ; 
27+ 
2628const  fixturesDir  =  path . join ( __dirname ,  '..' ,  '.fixtures' ) ; 
2729const  tmpDir  =  fs . mkdtempSync ( path . join ( process . env . TEMP  ||  os . tmpdir ( ) ,  'buildx-build-' ) ) ; 
2830const  tmpName  =  path . join ( tmpDir ,  '.tmpname-jest' ) ; 
@@ -41,6 +43,45 @@ afterEach(() => {
4143  rimraf . sync ( tmpDir ) ; 
4244} ) ; 
4345
46+ describe ( 'gitContext' ,  ( )  =>  { 
47+   const  originalEnv  =  process . env ; 
48+   beforeEach ( ( )  =>  { 
49+     jest . resetModules ( ) ; 
50+     process . env  =  { 
51+       ...originalEnv , 
52+       DOCKER_GIT_CONTEXT_PR_HEAD_REF : '' 
53+     } ; 
54+   } ) ; 
55+   afterEach ( ( )  =>  { 
56+     process . env  =  originalEnv ; 
57+   } ) ; 
58+   // prettier-ignore 
59+   test . each ( [ 
60+     // no format set 
61+     [ 'refs/heads/master' ,  undefined ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
62+     [ 'master' ,  undefined ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
63+     [ 'refs/pull/15/merge' ,  undefined ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/merge&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
64+     [ 'refs/tags/v1.0.0' ,  undefined ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/tags/v1.0.0&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
65+     [ 'refs/pull/15/merge' ,  undefined ,  true ,  'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/head&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
66+     // query format 
67+     [ 'refs/heads/master' ,  'query' ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
68+     [ 'master' ,  'query' ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
69+     [ 'refs/pull/15/merge' ,  'query' ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/merge&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
70+     [ 'refs/tags/v1.0.0' ,  'query' ,  false ,  'https://github.com/docker/actions-toolkit.git?ref=refs/tags/v1.0.0&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
71+     [ 'refs/pull/15/merge' ,  'query' ,  true ,  'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/head&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
72+     // fragment format 
73+     [ 'refs/heads/master' ,  'fragment' ,  false ,  'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
74+     [ 'master' ,  'fragment' ,  false ,  'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
75+     [ 'refs/pull/15/merge' ,  'fragment' ,  false ,  'https://github.com/docker/actions-toolkit.git#refs/pull/15/merge' ] , 
76+     [ 'refs/tags/v1.0.0' ,  'fragment' ,  false ,  'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] , 
77+     [ 'refs/pull/15/merge' ,  'fragment' ,  true ,  'https://github.com/docker/actions-toolkit.git#refs/pull/15/head' ] , 
78+   ] ) ( 'given %p and %p, should return %p' ,  async  ( ref : string ,  format ?: string ,  prHeadRef : boolean ,  expected : string )  =>  { 
79+     process . env . DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF  =  prHeadRef  ? 'true'  : '' ; 
80+     const  build  =  new  Build ( ) ; 
81+     expect ( await  build . gitContext ( ref ,  '860c1904a1ce19322e91ac35af1ab07466440c37' ,  format  as  GitContextFormat ) ) . toEqual ( expected ) ; 
82+   } ) ; 
83+ } ) ; 
84+ 
4485describe ( 'resolveImageID' ,  ( )  =>  { 
4586  it ( 'matches' ,  async  ( )  =>  { 
4687    const  imageID  =  'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9' ; 
0 commit comments