devonfw / ide

Tool to automate setup and update of development environment (esp. for Java projects).
Apache License 2.0
33 stars 102 forks source link

Git reset detection for modified files is not working #1379

Open jan-vcapgemini opened 4 months ago

jan-vcapgemini commented 4 months ago

Currently the method to detect a modified local repository before the actual git reset is not working as expected. The check for modified files e.g. git diff-index --quiet HEAD is returning an exit code of 1 if modified files were found.

https://github.com/devonfw/IDEasy/blob/9d89b236a0dd2aa389d700243d9373856d9cd838/cli/src/main/java/com/devonfw/tools/ide/context/GitContextImpl.java#L245-L252

This seems to work fine, but the run process itself will throw an exception if the exit code differs from 0.

https://github.com/devonfw/IDEasy/blob/9d89b236a0dd2aa389d700243d9373856d9cd838/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java#L146-L152

This looks like a conflict because I'm expecting the exit code 1 (modified files detected) to start the git reset. As the run process does not pass this exit code to my check, the whole reset fails.

Possible fix

The easiest fix would be to remove the git diff-index check and just start the reset without a check for isSuccessful.

hohwille commented 3 months ago

This seems to work fine, but the run process itself will throw an exception if the exit code differs from 0.

This is configurable via error handling: https://github.com/devonfw/IDEasy/blob/8e44c02fffb25707b176042d53d4c564113fc0f0/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java#L323-L338

Read the JavaDocs: https://github.com/devonfw/IDEasy/blob/8e44c02fffb25707b176042d53d4c564113fc0f0/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java#L21-L26

The default is THROW: https://github.com/devonfw/IDEasy/blob/8e44c02fffb25707b176042d53d4c564113fc0f0/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java#L52