Skip to content
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

Allowing to initiate (cdktf init) a project in an empty directory. #1697

Closed
ValAug opened this issue Apr 7, 2022 · 27 comments
Closed

Allowing to initiate (cdktf init) a project in an empty directory. #1697

ValAug opened this issue Apr 7, 2022 · 27 comments
Labels
enhancement New feature or request needs-reproduction stale An issue or pull request that has not been updated in a very long time waiting-on-answer

Comments

@ValAug
Copy link

ValAug commented Apr 7, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

References

@ValAug ValAug added enhancement New feature or request new Un-triaged issue labels Apr 7, 2022
@ansgarm
Copy link
Member

ansgarm commented Apr 7, 2022

Hi @ValAug 👋 This issue was about not being able to run cdktf init in a freshly cloned git repository because that one is not empty because of the .git directory, right?

@ValAug
Copy link
Author

ValAug commented Apr 7, 2022

Hello,

That's correct.

ERROR: Cannot initialize a project in a non-empty directory.

Sorry that made a mistake in the issue title

@ValAug
Copy link
Author

ValAug commented Apr 7, 2022

It looks like I have to delete what is created with the repo first then run cdktf init --template="typescript" for this work.

Still seen to be a good opportunity to enhance the whole process. We should be able to init the project without needing to delete what is created by GitHub

@jsteinich
Copy link
Collaborator

I just tried running git init followed by cdktf init and didn't run into any problems.
I'm wondering if there is a README.md file being created with a new project or potentially a LICENSE file. @ValAug are either of those present or is there something else?

@ValAug
Copy link
Author

ValAug commented Apr 8, 2022 via email

@ansgarm
Copy link
Member

ansgarm commented Apr 8, 2022

Hi @ValAug, quick question: Do you create the new repo based on a template that already contains some kind of CDKTF project? (You wouldn't need to run cdktf init in that case, it is only required to create a new project but not required to be run by e.g. different team members after they cloned that existing project).
We could make the latter more clear by detecting whether there's already a cdktf.json available and tell the user that they don't need to run init like they'd have to do when using Terraform directly.

@ValAug
Copy link
Author

ValAug commented Apr 8, 2022 via email

@jsteinich
Copy link
Collaborator

Unless there is some issue that we aren't aware of, you should have no problem running cdktf init in an empty directory.
@ValAug can you please run ls in the directory that you are trying to run cdktf init and let us know what it shows?

@ValAug
Copy link
Author

ValAug commented Apr 8, 2022 via email

@jsteinich
Copy link
Collaborator

What's strange is that I don't have any issues with this locally. I also can see the code which should already ignore a .git directory:

fs.readdirSync(dir).filter((f) => !f.startsWith(".") && f !== logFileName)

@ValAug what OS are you using?

@ValAug
Copy link
Author

ValAug commented Apr 10, 2022 via email

@jsteinich
Copy link
Collaborator

mkdir 1697
cd 1697
git init
cdktf init

@ValAug
Copy link
Author

ValAug commented Apr 10, 2022 via email

@jsteinich
Copy link
Collaborator

Is there a possible opportunity to be able to clone a brand new repo and initiate the CDKTF project in the future without receiving the error message that I am receiving ?

Absolutely. I'm just trying to get to the bottom of what's different with your process/environment. Cloning an empty git repo will have a .git directory, but the same is true after running git init. Creating a repo in the GitHub UI can result in some other files being created if you check various boxes. Some of those would prevent cdktf init from working. We can check for those files, but it didn't sound like you had any of those present.

I've tried both Linux and Windows without issue, but I'm unable to check on Mac. @ansgarm can you try this out please?

@ansgarm
Copy link
Member

ansgarm commented Apr 11, 2022

@jsteinich worked for me as well on OS X:

> mkdir test-git-init
> cd test-git-init
> git init
Initialized empty Git repository in /Users/ansgar/projects/playground/test-git-init/.git/
> ls -lAh
total 0
drwxr-xr-x  9 ansgar  staff   288B Apr 11 14:23 .git
> cdktf --version
0.10.1
> cdktf init --local
# worked

@ValAug
Copy link
Author

ValAug commented Apr 11, 2022 via email

@ansgarm
Copy link
Member

ansgarm commented Apr 12, 2022

Hi @ValAug,
could you create and link a public Github repo (which shows this behaviour after cloning) that I can clone to try to reproduce it locally on my machine?

@ansgarm ansgarm added waiting-on-answer needs-reproduction and removed new Un-triaged issue labels Apr 12, 2022
@ValAug
Copy link
Author

ValAug commented Apr 12, 2022 via email

@jsteinich
Copy link
Collaborator

In that example the problem is README.md. Should be easy enough to add an exception for that.

@ansgarm
Copy link
Member

ansgarm commented Apr 13, 2022

While we could ignore a README.md, we wouldn't be able to make this proposed change: #1315 without e.g. asking the user whether overwrite that file 😇

@ValAug
Copy link
Author

ValAug commented Apr 14, 2022 via email

@ansgarm
Copy link
Member

ansgarm commented Apr 14, 2022

Hi @ValAug,

no, that's no decision yet. I rather wanted to link to the other issue this proposal might collide with, to make sure we take that into consideration.

To me it would be perfectly fine to allow e.g. a README.md file until we work on the other issue and only then think about the overwriting vs. asking the user problem. It seems that it can happen quite easily that a user creates a new repository with a README.md file when using the Github UI for that.

ansgarm added a commit that referenced this issue Apr 14, 2022
…E.md

When creating a new Git repository via Github one can easily add a README.md resulting in an non-empty new git repo in which cdktf init won't work then

Related to #1697
@tgmatt
Copy link

tgmatt commented Apr 20, 2022

I recently came across this problem while trying cdktf out, and it begs the question; why can't it init in a non-empty directory if none of the files that exist conflict with what the init is trying to create? Surely you can just check the files it intends to create and fail if a conflict exists?

@ansgarm
Copy link
Member

ansgarm commented Apr 21, 2022

Hi @tgmatt, the cdktf-cli currently uses node-sscaff for the different templates we support (and for user defined "remote" templates) and that library does not currently support checking whether files exist (it will just overwrite them).

While we could technically solve this for static files in the template, it would be harder for files that are written programmatically via the .hooks.sscaff.js script. One example would be the package-lock.json file and node_modules directory that are created when executing npm install in a post hook in such a script.

Maybe extending our list of allowed files (currently Readme.md and hidden files [e.g. .git]) to more files that might appear from various workflows (i.e. when using certain Git tools or IDEs) could improve this further. For example here is the list of allowed files from Create React App – however, they don't share the custom template problem (which can introduce any file).

@github-actions
Copy link
Contributor

Hi there! 👋 We haven't heard from you in 30 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.

@github-actions github-actions bot added the stale An issue or pull request that has not been updated in a very long time label Nov 26, 2022
@github-actions
Copy link
Contributor

I'm closing this issue because we haven't heard back in 60 days. ⌛️ If you still need help, feel free to comment or reopen the issue!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2022
@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request needs-reproduction stale An issue or pull request that has not been updated in a very long time waiting-on-answer
Projects
None yet
Development

No branches or pull requests

4 participants