Skip to content

Conversation

@0237h
Copy link
Collaborator

@0237h 0237h commented Oct 25, 2024

If the user is choosing an existing directory for creating a new subgraph, ask for confirmation.
If the answer is negative, abort the process.

Closes #1370

@changeset-bot
Copy link

changeset-bot bot commented Oct 25, 2024

🦋 Changeset detected

Latest commit: e79d45c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphprotocol/graph-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@0237h 0237h marked this pull request as ready for review October 25, 2024 21:55
@0237h 0237h requested a review from YaroShkvorets October 30, 2024 14:00
@YaroShkvorets
Copy link
Collaborator

After confirming that I want to use the existing directory it proceeds but then fails with Error: Directory or file "weth" already exists. Should probably overwrite?

image

@0237h
Copy link
Collaborator Author

0237h commented Oct 31, 2024

After confirming that I want to use the existing directory it proceeds but then fails with Error: Directory or file "weth" already exists. Should probably overwrite?

Fixed in #4eaf6a2 thanks.

Also fixed when using --from-example flag.

@YaroShkvorets
Copy link
Collaborator

@0237h I think we should delete all files from the directory. Othewise we could be mixing different projects and/or committing a bunch of unrelated files into subgraph repository, which is not great.

Unless you can think of a scenario where we would want to keep any old files in the directory we are overwriting.

@0237h
Copy link
Collaborator Author

0237h commented Oct 31, 2024

I would argue that it could be more dangerous deleting files.

Right now, if you're not careful with the prompt, you'll end up overwriting/adding new files which isn't big deal. If we add deletion, one mistake and you could get files removed (any files).

Also there might be some use cases where you have ABIs in a subfolder that you might want to keep ?
Not entirely sure but in any case I would avoid deleting files and letting the user do it. Otherwise they should use a new directory, not existing one.

@YaroShkvorets
Copy link
Collaborator

Yes, I agree about deleting being dangerous. Although I'm still having hard time picturing when it would be useful to keep existing files in your repo.

The ideal flow would probably be checking if directory exists right after the prompt and requiring to enter the different directory name. We can still keep "overwrite yes/no" prompt when generating the project. Can be a separate issue if that's too much work.

@0237h 0237h merged commit d764867 into graphprotocol:main Nov 5, 2024
9 checks passed
@0237h 0237h deleted the fix/init-directory-already-exists branch November 5, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Directory already exists when trying to initialize a subgraph and point it to an existing directory

2 participants