@@ -24,13 +24,23 @@ function withRepo(run) {
2424 git ( "commit" , "-q" , "-m" , "c" ) ;
2525 return git ( "rev-parse" , "HEAD" ) . stdout . trim ( ) ;
2626 } ;
27+ // `files` null checks the index as it stands (git add -A would drop a gitlink with no checkout).
28+ const staged = ( files ) => {
29+ if ( files ) {
30+ for ( const [ name , contents ] of Object . entries ( files ) )
31+ writeFileSync ( join ( dir , name ) , contents ) ;
32+ git ( "add" , "-A" ) ;
33+ }
34+ const result = spawnSync ( SCRIPT , [ ] , { cwd : dir , env, encoding : "utf-8" } ) ;
35+ return { ok : result . status === 0 , stderr : result . stderr ?? "" } ;
36+ } ;
2737 const range = ( base , head ) => {
2838 const result = spawnSync ( SCRIPT , [ "--range" , base , head ] , { cwd : dir , env, encoding : "utf-8" } ) ;
2939 return { ok : result . status === 0 , stderr : result . stderr ?? "" } ;
3040 } ;
3141 try {
3242 git ( "init" , "-q" ) ;
33- run ( { commit, range, dir, git } ) ;
43+ run ( { commit, staged , range, dir, git } ) ;
3444 } finally {
3545 rmSync ( dir , { recursive : true , force : true } ) ;
3646 }
@@ -172,4 +182,48 @@ describe("check-large-files", () => {
172182 assert . equal ( range ( base , head ) . ok , false ) ;
173183 } ) ;
174184 } ) ;
185+
186+ it ( "staged mode rejects a large binary and passes text" , ( ) => {
187+ withRepo ( ( { commit, staged } ) => {
188+ commit ( { "seed.txt" : "x" } ) ;
189+ const { ok, stderr } = staged ( { "big.bin" : bigBinary , "big.txt" : bigText } ) ;
190+ assert . equal ( ok , false ) ;
191+ assert . match ( stderr , / b i g \. b i n / ) ;
192+ assert . doesNotMatch ( stderr , / b i g \. t x t / ) ;
193+ } ) ;
194+ } ) ;
195+
196+ it ( "staged mode sizes a file named like revision syntax, not the file it aliases" , ( ) => {
197+ withRepo ( ( { commit, staged } ) => {
198+ commit ( { "clip.bin" : "small" } ) ;
199+ const { ok, stderr } = staged ( { "0:clip.bin" : bigBinary } ) ;
200+ assert . equal ( ok , false ) ;
201+ assert . match ( stderr , / 0 : c l i p \. b i n / ) ;
202+ } ) ;
203+ } ) ;
204+
205+ it ( "staged mode checks modified and type-changed files" , ( ) => {
206+ withRepo ( ( { commit, staged, dir } ) => {
207+ writeFileSync ( join ( dir , "target" ) , "t" ) ;
208+ symlinkSync ( "target" , join ( dir , "link.bin" ) ) ;
209+ commit ( { "clip.bin" : "small" } ) ;
210+ rmSync ( join ( dir , "link.bin" ) ) ;
211+ const { ok, stderr } = staged ( { "clip.bin" : bigBinary , "link.bin" : bigBinary } ) ;
212+ assert . equal ( ok , false ) ;
213+ assert . match ( stderr , / c l i p \. b i n / ) ;
214+ assert . match ( stderr , / l i n k \. b i n / ) ;
215+ } ) ;
216+ } ) ;
217+
218+ it ( "skips a submodule whose commit is not in this repository" , ( ) => {
219+ withRepo ( ( { commit, staged, range, git } ) => {
220+ const base = commit ( { "seed.txt" : "x" } ) ;
221+ const child = "1234567890abcdef1234567890abcdef12345678" ;
222+ git ( "update-index" , "--add" , "--cacheinfo" , `160000,${ child } ,sub` ) ;
223+ assert . equal ( staged ( null ) . ok , true ) ;
224+ git ( "commit" , "-q" , "-m" , "sub" ) ;
225+ const head = git ( "rev-parse" , "HEAD" ) . stdout . trim ( ) ;
226+ assert . equal ( range ( base , head ) . ok , true ) ;
227+ } ) ;
228+ } ) ;
175229} ) ;
0 commit comments