Skip to content

allow organize to move repositories into a child directory of their current location #1172

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

Merged
merged 2 commits into from
Dec 11, 2023

Conversation

jcgruenhage
Copy link
Contributor

I've run into a situation, where I had cloned a repo into a location and the canonicalized destination was a subpath of that location. ein tool organize --execute was unhappy about that:

~/dev 
❯ ein t organize --execute
 10:00:35 organize Moving ./example.org/foo to /path/to/destination/example.org/foo/foo
 10:00:35 organize Error when handling directory "./example.org/foo": Invalid argument (os error 22)
Error: Failed to handle 1 repositories

This patch moves directories twice, allowing for things like this to work out just fine:

~/dev 
❯ ein t organize --execute
 10:04:41 organize Moving ./example.org/foo to /path/to/destination/example.org/foo/foo

@Byron
Copy link
Member

Byron commented Dec 11, 2023

Thanks a lot for the fix! I wasn't aware of this issue yet either.

Now I wonder if you'd consider making the tempdir-indirection dependent on whether or not destination is actually a subdir of the source worktree?

This would probably require to perform a strip_prefix() check on the canonicalized version of workdir, but overall that should be cheaper than creating temporaries all the time. As a side-effect, that would make really clear why the temporary directory is created in the first place, just by looking at the code.

Thanks for your consideration.

@jcgruenhage
Copy link
Contributor Author

Yep, sounds good to me, will look into it, should be easy enough.

@Byron Byron marked this pull request as draft December 11, 2023 10:08
@jcgruenhage jcgruenhage force-pushed the organize-into-own-child branch from 939daab to 15193a7 Compare December 11, 2023 10:12
@jcgruenhage jcgruenhage marked this pull request as ready for review December 11, 2023 10:35
…ame` to `./repo-name/actual-repo-name`. (GitoxideLabs#1172)

Previously such renames would fail as a directory can't be moved into a sub-directory of itself.
@Byron
Copy link
Member

Byron commented Dec 11, 2023

Thanks a lot!

I have added a journey test that actually made canonicalisation necessary. When CI is green, this PR will be merged, but please feel free to verify it locally once more as you see fit.

@Byron Byron merged commit 84c998b into GitoxideLabs:main Dec 11, 2023
@jcgruenhage jcgruenhage deleted the organize-into-own-child branch December 11, 2023 12:46
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.

2 participants