Skip to content

Commit

Permalink
Bug/#736-gitignore block (#788)
Browse files Browse the repository at this point in the history
* fix resolving .gitignore files
  • Loading branch information
amitgilad3 authored and GiladShoham committed Feb 18, 2018
1 parent 1362d21 commit a8a9589
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- introduced a new command `bit untag` for reverting un-exported tags.
- init local scope inside .git
- support vue files
- [#736](https://github.com/teambit/bit/issues/736) - .gitignore is blocking everything

## [0.12.5] - 2018-02-06

Expand Down
27 changes: 13 additions & 14 deletions src/api/consumer/lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default (async function addAction(
override: boolean
): Promise<Object> {
const warnings = {};

let gitIgnore;
/**
* validatePaths - validate if paths entered by user exist and if not throw error
*
Expand Down Expand Up @@ -196,7 +196,7 @@ export default (async function addAction(
});
}

async function addOneComponent(componentPathsStats: Object, consumer: Consumer, gitIgnoreFiles: string[]) {
async function addOneComponent(componentPathsStats: Object, consumer: Consumer) {
const bitMap: BitMap = consumer.bitMap;
// remove excluded files from file list
async function removeExcludedFiles(mapValues, excludedList) {
Expand Down Expand Up @@ -282,13 +282,14 @@ export default (async function addAction(

const matches = await glob(path.join(relativeComponentPath, '**'), {
cwd: consumer.getPath(),
nodir: true,
ignore: gitIgnoreFiles
nodir: true
});

if (!matches.length) throw new EmptyDirectory();
const filteredMatches = gitIgnore.filter(matches);

if (!filteredMatches.length) throw new EmptyDirectory();

let files = matches.map((match: PathOsBased) => {
let files = filteredMatches.map((match: PathOsBased) => {
return { relativePath: pathNormalizeToLinux(match), test: false, name: path.basename(match) };
});

Expand Down Expand Up @@ -371,21 +372,20 @@ export default (async function addAction(
}

// add ignore list
const gitIgnore = ignore().add(ignoreList);
gitIgnore = ignore().add(ignoreList);

// check unknown test files
const missingFiles = getMissingTestFiles(tests);
if (!R.isEmpty(missingFiles)) throw new PathNotExists(missingFiles);

let componentPathsStats = {};
let resolvedComponentPathsWithGitIgnore = R.flatten(
await Promise.all(componentPaths.map(componentPath => glob(componentPath)))
);
resolvedComponentPathsWithGitIgnore = gitIgnore.filter(resolvedComponentPathsWithGitIgnore);

const resolvedComponentPathsWithoutGitIgnore = R.flatten(
await Promise.all(componentPaths.map(componentPath => glob(componentPath)))
);

const resolvedComponentPathsWithGitIgnore = gitIgnore.filter(resolvedComponentPathsWithoutGitIgnore);

// Run diff on both arrays to see what was filtered out because of the gitignore file
const diff = arrayDiff(resolvedComponentPathsWithGitIgnore, resolvedComponentPathsWithoutGitIgnore);

Expand All @@ -412,8 +412,7 @@ export default (async function addAction(
{
[onePath]: componentPathsStats[onePath]
},
consumer,
ignoreList
consumer
);
});

Expand All @@ -430,7 +429,7 @@ export default (async function addAction(
// when a user enters more than one directory, he would like to keep the directories names
// so then when a component is imported, it will write the files into the original directories

const addedOne = await addOneComponent(componentPathsStats, consumer, ignoreList);
const addedOne = await addOneComponent(componentPathsStats, consumer);
if (!R.isEmpty(addedOne.files)) {
const addedResult = addOrUpdateExistingComponentsInBitMap(consumer.projectPath, bitMap, addedOne);
added.push(addedResult);
Expand Down

0 comments on commit a8a9589

Please sign in to comment.