New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New application with collection already containing a .gitignore fails #1628
Comments
If you're using |
FindingsThe main call to init git passes but when the next which is to create gitignore file fails. if (!isDryRunEnabled) {
if (!shouldSkipGit) {
await initializeGitRepository(projectDirectory); // passes and setups all necessary git init actions
await createGitIgnoreFile(projectDirectory); // fails as it assumes no .gitignore file would exists
}
printCollective();
} Referencing file: nest-cli/actions/new.action.ts Line 207 in 94b0c03
The createGitIgnoreFile function does not consider the fact the files copied through schematics may already contain a .gitignore file. I think this is written this way as the default application strucuture in @nestjs/schmatics does not include the .gitignore file. In my collection overide of the schematics I have provided my own gitignore and its causing failure in completion of command. /**
* Write a file `.gitignore` in the root of the newly created project.
* `.gitignore` available in `@nestjs/schematics` cannot be published to
* NPM (needs to be investigated).
*
* @param dir Relative path to the project.
* @param content (optional) Content written in the `.gitignore`.
*
* @return Resolves when succeeds, or rejects with any error from `fn.writeFile`.
*/
const createGitIgnoreFile = (dir: string, content?: string) => {
const fileContent = content || defaultGitIgnore;
const filePath = join(process.cwd(), dir, '.gitignore');
return promisify(fs.writeFile)(filePath, fileContent);
}; |
Also I was creating a new app in a non existing directory Just FYI: I was looking into the implementation it looks like there is some attempt but never completed, as there is an option of passing custom content but the main caller never does such a thing along with the fact there is a possibility that the file may already exist after copying the structure from schematics provided. Would it be okay that I provide a pull request for this? |
If it's non-breaking and easy to maintain, I'd say go for it :) |
Ok. Will do |
@jmcdo29 |
Tracking this here #1630 |
Is there an existing issue for this?
Current behavior
When setting up a new application using a collection that already contains a .gitignore file. The git init process would fail.
Minimum reproduction code
https://gist.github.com/maxgaurav/c6260d956d5fb7d124f565959406e957
Steps to reproduce
Expected behavior
When a .gitignore file already exists it should not try to overwrite with default git content. This actions leads to
Package version
8.2.5
NestJS version
No response
Node.js version
v16.14.2
In which operating systems have you tested?
Other
It looks like the action where .gitignore is being initialized is not considering the fact a .gitignore file can already be there
The text was updated successfully, but these errors were encountered: