-
-
Notifications
You must be signed in to change notification settings - Fork 385
fix: submodule worktree incorrect with symlinked .git
dir (#2052)
#2182
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
base: main
Are you sure you want to change the base?
Conversation
Without having looked at it in detail, it's true that |
Would it be a breaking change if we use absolute paths for the worktree_dir instead? |
Absolutely, at least when done unconditionally. But maybe this even should be done when it makes sense? Would the case here qualify using real paths? |
0533ad7
to
52f54f2
Compare
Looks like I got the tests to pass! However, I'm not sure how I should create the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing this!
This is not really a review of the PR as a whole, I just noticed that it looked like I could help out with a couple of things.
Looks like I got the tests to pass! However, I'm not sure how I should create the
.tar
archive.
I've fixed a bug in the shell script--see below--and I'll push that followed by a regenerated archive. (If it were regenerated first, it would need to be regenerated again after the fix to the script, since the check for whether a committed archive is up to date is based on a hash of the fixture script used to generate it.)
The old archive had a path prefixed by
/home/aru
which was weird
I think this is worth looking into, assuming it's unintentional. I could be misunderstanding, but I think the intent of the code here is not to cause an absolute path to be written into the repository for the submodule, at least not in the fixture. I have not looked into this (and I don't have time to do so at the moment).
If there is such a path in the committed .tar
archive that will be present in the immediately forthcoming commits, it would probably start with /home/ek
(since my username is ek
).
Please note that, other than the specific part of the shell script that I've modified as described below, I have not really reviewed this PR at all--I'm only submitting this as a review because it allows me to comment on a specific line of code.
This test failure occurs on CI on macOS:
But I don't think the problem is macOS-specific. I suspect it will happen whenever we don't set This arises from the problem you noticed a hint of in #2182 (comment), regarding the inclusion of a hard-coded path to your home directory when you tried generating the archives. In addition, this path is somehow being appended--maybe as though it were a relative path?--to Feel free to rewind (i.e. drop) e1d9ae3, of course, if it turns out to be useful to do so. (By itself removing that won't fix whatever is causing this, though.) If the behavior of hard-coding an absolute path that is specific to the current machine in the fixture is really intended, then this could be solved by adding the fixture archive to the appropriate Of course, all of that is still only applicable if the behavior of the fixture script (and associated tests) is as intended, such that the generated fixture really should hard-code an absolute path that is only correct on the system where it is run. cc @Byron |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for tackling this! The code itself looks mostly good to me, so I think the real issue here comes from the way the tests work.
I hope my comments in that regard make sense, but if not, I could also take it form here if you like. Just let me know.
Thanks again!
Thanks @Byron, @EliahKagan! The PR is ready for another of review:) Edit: sorry, let me get CI to pass 😅 |
Co-authored-by: Eliah Kagan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for taking another look!
I now spent some time with this and realise that some changes are needed.
The most important one is a test which at least makes clear what's under test, and something as complex as a status isn't that.
Thanks again for bearing with me here - if you are out of time I could also take it from here.
// the reason we use realpath instead of gix_path::normalize here is because there | ||
// could be any intermediate symlinks (for example due to a symlinked .git | ||
// directory) | ||
worktree_dir = gix_path::realpath(&wt_path).ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using realpath should be conditional, based on if the path exists or not.
Because what's under test here really is that normalize
can mess up paths that have symlinks in them, yielding an invalid path.
So I think there should even be a warning in gix_path::normalize()
to tell people to check if the path is still valid.
In a follow-up, one should check all call-sites as they will have the same issue.
} | ||
|
||
#[test] | ||
fn submodule_in_symlinked_dir() -> crate::Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should be removed in favor of specific tests which make clear what's under test.
This test 'only' tests if the status succeeds, otherwise it fails with something like.
Error: IndexAsWorktreeWithRenames(TrackedFileModifications(SubmoduleStatus { rela_path: "m1", source: SubmoduleStatus(NextStatusItem(IndexWorktree(IndexAsWorktreeWithRenames(DirWalk(WorktreeRootIsFile { root: "tests/fixtures/generated-do-not-edit/make_submodule_with_symlinked_git_dir/3844911589-unix/m1" }))))) }))
if let Some(rel_path) = worktree_dir.as_deref().and_then(|p| p.strip_prefix(current_dir).ok()) { | ||
worktree_dir = Some(rel_path.to_path_buf()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have this, there must be a test for this. Maybe it's OK to leave it out for now, since this symlink handling is already quite a special case.
fixes #2052
My fix introduced a regression. Looks like we never return relative paths for
repo.workdir()
. One way I see to fix this is by making the path relative tocwd
, but not sure if this is desired. Any thoughts on how we can work around this?