Skip to content

Move file to another directory #5373

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Move file to another directory #5373

wants to merge 9 commits into from

Conversation

Jenson3210
Copy link
Contributor

What's changed?

Added a recipe that moves files to another directory (resulting in renamed directories if all files are moved)

What's your motivation?

As there could be many use cases to in bulk rename directories, move files...

Anyone you would like to review specifically?

@timtebeek

Any additional context

Requested in slack

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite May 3, 2025
@Jenson3210 Jenson3210 self-assigned this May 3, 2025
@Jenson3210 Jenson3210 added the recipe Requested Recipe label May 3, 2025
@Jenson3210 Jenson3210 marked this pull request as draft May 3, 2025 23:05
Jenson3210 and others added 2 commits May 4, 2025 01:05
@shanman190
Copy link
Contributor

I spy *nix specific paths which would also make these tests fail when executed on a Windows machine or when using Windows based paths.

@Jenson3210
Copy link
Contributor Author

Jenson3210 commented May 4, 2025

I spy *nix specific paths which would also make these tests fail when executed on a Windows machine or when using Windows based paths.

@shanman190
🙏 thanks for the observation!
I indeed needed to check still with @timtebeek how Windows would behave on the parser. Was kinda hoping parsing mapped to single notation. But apparently not then 😖

I did write some behaviour to how I hope it is working plus the tests, but need to check :)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@shanman190
Copy link
Contributor

@Jenson3210 , is the plan to only support *nix style paths for the moveTo option? Otherwise, that probably needs some adaptation to support Windows-style paths.

@Jenson3210
Copy link
Contributor Author

@shanman190 yes indeed.

As the SourcePath is always relative (still have to check if this is the case with Tim) to the repo root, I was thinking to have 1 uniform syntax for moveTo math (absolute inside repo root or relative to the current file/folder)

Otherwise our recipes using this one always have to call it with a syntax for Windows and one for Unix, resulting in 2 recipes in the recipe list or complexer custom recipes.

@shanman190
Copy link
Contributor

Or you choose to accept either and normalize the input within the recipe to allow the user to specify either, but handle it internally in a uniform way. This is what is done internally within PathUtils for matching as an example.

@Jenson3210
Copy link
Contributor Author

Adapted the recipe to allow for window paths also in the moveTo option (and folder option)

@Jenson3210 Jenson3210 marked this pull request as ready for review May 28, 2025 11:12
@Jenson3210 Jenson3210 moved this from In Progress to Ready to Review in OpenRewrite May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Requested Recipe
Projects
Status: Ready to Review
Development

Successfully merging this pull request may close these issues.

3 participants