Generator: Better integration with Git

Created on 22 Nov 2019  路  3Comments  路  Source: asyncapi/generator

Problem

One of the common problems when generating code is the fear of removing business logic when regenerating code in an existing project. To avoid this, we introduced the -n, --no-overwrite option but this doesn't prevent people from forgetting about it or forgetting about a path they don't want to overwrite, and accidentally deleting code they can't recover.

Solution

Check if the directory is a git repo. If that's the case, the generator should not allow you to regenerate the project if there are unstaged changes in the working tree. We can also provide a -f, --force option to eliminate this restriction.

I'm also thinking that, when the project is not a git repo, it shouldn't allow you to generate code in a directory that already contains files. Again, this restriction can be removed using -f, --force.

enhancement help wanted

All 3 comments

That would be a breaking change right? The default behaviour of the generator would change

Yep but it doesn't really matter yet as we're on 0.x versions. Breaking changes must be expected.

Feature implemented and soon will be released.

From now on, when you generate files:

  • To non-empty directory, you get an error with information that you can lose some of your work as it can get overwritten.
  • To a directory in a git repository, you get an error that you might lose some of your work but only in case you have some unstaged changes

We also introduced new flag in CLI called --force-write (it is also supported on a library level) and it will allow you to ignore rules provided by this feature

@handrews I saw you like the idea for having such a feature, so just letting you know it is done

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aravindajju picture aravindajju  路  9Comments

fmvilas picture fmvilas  路  9Comments

jonaslagoni picture jonaslagoni  路  5Comments

fmvilas picture fmvilas  路  8Comments

uraala picture uraala  路  10Comments