Commit 0324283
committed
path.c: translate Windows paths recorded by Windows git on POSIX hosts
When `git worktree add` is run from native Windows, git writes
absolute paths into the worktree's `.git` file, into
`<commondir>/worktrees/<id>/gitdir`, and (when present) into
`<commondir>/commondir`, in `<x>:/...` or `<x>:\...` form. Reading
those files back from a non-Windows-native build of git fails because
neither form is meaningful on POSIX, so the worktree appears broken
even though every byte of it is reachable - the most common scenario
being a worktree on a Windows drive opened from inside WSL2 (where
the Windows filesystem is mounted at `/mnt/<x>/`) or from Cygwin/MSYS
(where it is `/cygdrive/<x>/`).
Add a small helper `translate_windows_path()` that recognises this
shape at the start of a path and rewrites it to the POSIX mount form
appropriate for the current build (`/cygdrive/<x>/` on Cygwin,
`/mnt/<x>/` everywhere else), converting any backslashes in the
remainder to forward slashes. Call it at the three places where
non-Windows-native git reads a recorded worktree-related path back
from disk:
* `read_gitfile_gently()` - the `gitdir:` line in a worktree's
`.git` file.
* `get_common_dir_noenv()` - the `commondir` file inside a
worktree's git directory, which points at the main repo.
* `get_linked_worktree()` - the `gitdir` file inside
`<commondir>/worktrees/<id>/`, which points at the worktree's
`.git` link.
Translation only happens for `<x>:/` or `<x>:\` where `<x>` is a
single ASCII letter; anything else is left alone. The helper is a
no-op on `GIT_WINDOWS_NATIVE` builds, where the input is already in
native form. On non-WSL Linux hosts the translation still produces
a syntactically valid POSIX path; if the corresponding `/mnt/<x>/`
mount does not exist, the next stat()/open() fails as it would have
without translation - i.e. the change cannot make a working
configuration stop working.
Add a `translate_windows_path` subcommand to the path-utils test tool
and cover it in `t/t0060-path-utils.sh`. The test fixtures pick the
expected prefix from the CYGWIN prereq so the same suite passes on
Linux and Cygwin builds.
Signed-off-by: johnnyshields <27655+johnnyshields@users.noreply.github.com>1 parent 94f0577 commit 0324283
6 files changed
Lines changed: 120 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
21 | 64 | | |
22 | 65 | | |
23 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
9 | 26 | | |
10 | 27 | | |
11 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
| |||
1009 | 1010 | | |
1010 | 1011 | | |
1011 | 1012 | | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
1012 | 1028 | | |
1013 | 1029 | | |
1014 | 1030 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
401 | 401 | | |
402 | 402 | | |
403 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
404 | 413 | | |
405 | 414 | | |
406 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
611 | 611 | | |
612 | 612 | | |
613 | 613 | | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
614 | 646 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| |||
0 commit comments