Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for applying parent .gitignore files when archiving directories for deployment (e.g., in App Hosting and Cloud Run). It introduces a gitIgnoreRoot option to fsAsync.readdirRecursive to traverse and stack .gitignore rules from parent directories up to the specified root. Feedback on the changes suggests wrapping the statSync check in parentGitIgnores with a try-catch block to prevent potential filesystem permission errors from crashing the directory traversal.
| if (!existsSync(gitIgnorePath) || !statSync(gitIgnorePath).isFile()) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Calling statSync(gitIgnorePath) directly can throw an error if there are permission issues (EACCES) or other filesystem restrictions on any of the parent directories, which would crash the entire directory traversal. Wrapping this check in a try-catch block ensures that any such filesystem errors are caught gracefully and logged as debug messages, allowing the traversal to continue safely.
try {
if (!existsSync(gitIgnorePath) || !statSync(gitIgnorePath).isFile()) {
continue;
}
} catch (e: unknown) {
logger.debug(`Error checking .gitignore file at ${gitIgnorePath}:`, e);
continue;
}There was a problem hiding this comment.
if we can not load the .gitignore for a project we should fail the deployment/build because it's unsafe to proceed. We might accidentally upload files the user doesnt want.
04af65a to
2d3c147
Compare
…ubfolder A Cloud Run source deploy of an app in a subfolder (e.g. firebase.json + functions/ + web/) zips only that subfolder, and the zip only read .gitignore files inside it. Files ignored by a .gitignore higher up, like the project's top-level one, were uploaded, built, and could be served. App Hosting's source deploys and local builds walk from the project's root, so they already excluded them. readdirRecursive gets a gitIgnoreRoot option that also applies the .gitignore files from that directory down to the one being walked, like git does. createSourceDeployArchive passes the project's directory through it, in place of its unused targetSubDir parameter. A .gitignore that can't be read now fails the walk instead of being skipped, since skipping it could upload files that the user meant to leave out.
2d3c147 to
a32dfdf
Compare
Description
Stacked on #11396. A Cloud Run source deploy of an app in a subfolder (e.g.
firebase.json+functions/+web/) zips only that subfolder, and only read.gitignorefiles inside it. Files ignored by a.gitignorehigher up, like the project's top-level one, were uploaded, built, and could be served. App Hosting source deploys and local builds already exclude them.The zip now also applies the
.gitignorefiles from the project's root down to the folder it zips, like git.readdirRecursivegets agitIgnoreRootoption for this, andcreateSourceDeployArchivetakes the project's directory in place of its unusedtargetSubDirparameter.Scenarios Tested
.gitignore, a deeper.gitignorenegation that overrides it, and a folder outside the root.web/with aweb/public/*.pemfile that only the top-level.gitignoreignores:Sample Commands
# With "rootDir": "web" on the service in firebase.json: firebase deploy --only run:web