@@ -30,16 +30,16 @@ define(function (require, exports, module) {
3030 Dialogs = require ( "widgets/Dialogs" ) ,
3131 Commands = require ( "command/Commands" ) ,
3232 FileSystemError = require ( "filesystem/FileSystemError" ) ,
33- StringUtils = require ( "utils/StringUtils" ) ,
3433 SpecRunnerUtils = require ( "spec/SpecRunnerUtils" ) ,
3534 _ = require ( "thirdparty/lodash" ) ;
3635
3736
3837 describe ( "LegacyInteg:ProjectManager" , function ( ) {
3938
40- var testPath = SpecRunnerUtils . getTestPath ( "/spec/ProjectManager-test-files" ) ,
39+ let testPath = SpecRunnerUtils . getTestPath ( "/spec/ProjectManager-test-files" ) ,
4140 tempDir = SpecRunnerUtils . getTempDirectory ( ) ,
4241 testWindow ,
42+ FileUtils ,
4343 brackets ;
4444
4545 beforeAll ( async function ( ) {
@@ -56,6 +56,7 @@ define(function (require, exports, module) {
5656 brackets = testWindow . brackets ;
5757 ProjectManager = testWindow . brackets . test . ProjectManager ;
5858 CommandManager = testWindow . brackets . test . CommandManager ;
59+ FileUtils = testWindow . brackets . test . FileUtils ;
5960 FileSystem = testWindow . brackets . test . FileSystem ;
6061
6162 await SpecRunnerUtils . loadProjectInTestWindow ( tempDir ) ;
@@ -595,6 +596,138 @@ define(function (require, exports, module) {
595596 } , 10000 ) ;
596597 } ) ;
597598
599+ async function _createDirTree ( baseDir , fileList ) {
600+ for ( let file of fileList ) {
601+ let fileEntry = FileSystem . getFileForPath ( baseDir + file ) ;
602+ await jsPromise ( FileUtils . writeText ( fileEntry , "hello" , true ) ) ;
603+ }
604+ }
605+
606+ async function _validateNestedGitIgnore ( ignorePattern , checkIgnoresFiles , checkNotIgnored ) {
607+ await SpecRunnerUtils . deletePathAsync ( `${ tempDir } /ignoreTest` , true , FileSystem ) ;
608+ const gitIgnoreFilePath = `${ tempDir } /ignoreTest/.gitignore` ;
609+ await SpecRunnerUtils . deletePathAsync ( gitIgnoreFilePath , true , FileSystem ) ;
610+ for ( let file of checkIgnoresFiles ) {
611+ await SpecRunnerUtils . ensureExistsDirAsync ( window . path . dirname ( `${ tempDir } /ignoreTest/${ file } ` ) ) ;
612+ }
613+ for ( let file of checkNotIgnored ) {
614+ await SpecRunnerUtils . ensureExistsDirAsync ( window . path . dirname ( `${ tempDir } /ignoreTest/${ file } ` ) ) ;
615+ }
616+
617+ await _createDirTree ( `${ tempDir } /ignoreTest/` , checkIgnoresFiles ) ;
618+ await _createDirTree ( `${ tempDir } /ignoreTest/` , checkNotIgnored ) ;
619+ // now check if we get everything
620+ await awaitsFor ( async ( ) => {
621+ const allFiles = await jsPromise ( ProjectManager . getAllFiles ( ) ) ;
622+ let foundItems = 0 ;
623+ for ( let file of allFiles ) {
624+ for ( let fileName of checkIgnoresFiles ) {
625+ if ( `${ tempDir } /ignoreTest/${ fileName } ` === file . fullPath ) {
626+ foundItems ++ ;
627+ }
628+ }
629+ for ( let fileName of checkNotIgnored ) {
630+ if ( `${ tempDir } /ignoreTest/${ fileName } ` === file . fullPath ) {
631+ foundItems ++ ;
632+ }
633+ }
634+ }
635+ return foundItems === ( checkIgnoresFiles . length + checkNotIgnored . length ) ;
636+ } , "Getting all files without nested gitignore" , 2000 , 100 ) ;
637+ // now create the git ignore file
638+ await jsPromise ( SpecRunnerUtils . createTextFile ( gitIgnoreFilePath , ignorePattern , FileSystem ) ) ;
639+ // now check if ignore is as expected
640+ await awaitsFor ( async ( ) => {
641+ const allFiles = await jsPromise ( ProjectManager . getAllFiles ( ) ) ;
642+ let foundItems = 0 ;
643+ for ( let file of allFiles ) {
644+ for ( let fileName of checkIgnoresFiles ) {
645+ if ( `${ tempDir } /ignoreTest/${ fileName } ` === file . fullPath ) {
646+ foundItems ++ ;
647+ }
648+ }
649+ }
650+ return foundItems === 0 ;
651+ } , "Getting all files with nested gitignore" , 2000 , 100 ) ;
652+ await awaitsFor ( async ( ) => {
653+ const allFiles = await jsPromise ( ProjectManager . getAllFiles ( ) ) ;
654+ let foundItems = 0 ;
655+ for ( let file of allFiles ) {
656+ for ( let fileName of checkNotIgnored ) {
657+ if ( `${ tempDir } /ignoreTest/${ fileName } ` === file . fullPath ) {
658+ foundItems ++ ;
659+ }
660+ }
661+ }
662+ return foundItems === checkNotIgnored . length ;
663+ } , "Getting all files that are not ignored" , 2000 , 100 ) ;
664+
665+ await SpecRunnerUtils . deletePathAsync ( `${ tempDir } /ignoreTest` , true , FileSystem ) ;
666+ }
667+
668+ it ( "should gitignore bare pattern in ProjectManager.getAllFiles with nested gitIgnore" , async function ( ) {
669+ await _validateNestedGitIgnore ( "xx" , [
670+ "xx/yy.txt" ,
671+ "yy/xx/yy.txt"
672+ ] , [
673+ "yy/xxs/yy.txt" ,
674+ "xx.txt" ,
675+ "xxs/xxy/yy.txt"
676+ ] ) ;
677+ } , 10000 ) ;
678+
679+ it ( "should gitignore base dir pattern in ProjectManager.getAllFiles with nested gitIgnore" , async function ( ) {
680+ await _validateNestedGitIgnore ( "/xx" , [
681+ "xx/yy.txt" ,
682+ "xx/c/yy.txt"
683+ ] , [
684+ "yy/xx/yy.txt" ,
685+ "yy/xx.txt"
686+ ] ) ;
687+ } , 10000 ) ;
688+
689+ it ( "should gitignore specific extension pattern in ProjectManager.getAllFiles with nested gitIgnore" , async function ( ) {
690+ await _validateNestedGitIgnore ( "/xx/**/*.yml" , [
691+ "xx/yy.yml" ,
692+ "xx/c/yy.yml"
693+ ] , [
694+ "nonBase/xx/c/yy.yml" ,
695+ "xx/yy.txt" ,
696+ "xx/c/yy.txt"
697+ ] ) ;
698+ } , 10000 ) ;
699+
700+ it ( "should gitignore negation pattern in ProjectManager.getAllFiles with nested gitIgnore" , async function ( ) {
701+ await _validateNestedGitIgnore ( "!xx" , [
702+ ] , [
703+ "xx/yy.txt" ,
704+ "yy/xx/yy.txt" ,
705+ "yy/xxs/yy.txt" ,
706+ "xx.txt" ,
707+ "xxs/xxy/yy.txt"
708+ ] ) ;
709+
710+ await _validateNestedGitIgnore ( "!/xx" , [
711+ ] , [
712+ "xx/yy.txt" ,
713+ "xx/c/yy.txt" ,
714+ "yy/xx/yy.txt" ,
715+ "yy/xx.txt"
716+ ] ) ;
717+ } , 10000 ) ;
718+
719+ // the below tests should work according to gitignore spec, but the git ignore library we use dont
720+ // handle negation very well.
721+ // it("should gitignore negated mixed extension pattern in ProjectManager.getAllFiles with nested gitIgnore", async function () {
722+ // await _validateNestedGitIgnore("/xx\n!/xx/**/*.yml",[
723+ // "xx/yy.txt",
724+ // "xx/c/yy.js"
725+ // ],[
726+ // "xx/yy.yml",
727+ // "xx/c/yy.yml"
728+ // ]);
729+ // }, 10000);
730+
598731 describe ( "Project, file and folder download" , function ( ) {
599732 if ( Phoenix . browser . isTauri ) {
600733 it ( "Not tested: download project is not present desktop local file system" , async function ( ) { } ) ;
0 commit comments