Repository navigation
Commit 920147e
committed
worktree repair: avoid breaking unrelated .git file and gitdir
Currently, `repair_gitfile()` does not verify whether the worktree ID
recorded in the .git file matches the worktree being repaired, which
can result in the corruption of an unrelated .git file. For instance,
if two worktree directories are swapped without using 'git worktree
move', running 'git worktree repair' in the main worktree accidentally
swaps the links between their .git files and gitdirs.
`repair_worktree_at_path()` proceeds even if it fails to infer the
gitdir path. This can result in the corruption of an unrelated
gitdir. For instance, if we copied a linked worktree to a new location
X, running 'git worktree repair X' in a working tree which does not
belong to the original repository can accidentally overwrite the
gitdir in the original repository (the scope of impact should be
limited to the repository where the command was executed).
Resolve these issues by validating the worktree ID and stopping the
repair when the ID does not match or the gitdir path cannot be
inferred.
Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>1 parent dc7ebb4 commit 920147e
2 files changed
Lines changed: 41 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 63 | + | |
| 64 | + | |
68 | 65 | | |
69 | 66 | | |
70 | 67 | | |
| |||
89 | 86 | | |
90 | 87 | | |
91 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
| |||
113 | 122 | | |
114 | 123 | | |
115 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
116 | 137 | | |
117 | 138 | | |
118 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
643 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
644 | 648 | | |
645 | 649 | | |
646 | 650 | | |
| |||
692 | 696 | | |
693 | 697 | | |
694 | 698 | | |
695 | | - | |
| 699 | + | |
696 | 700 | | |
| 701 | + | |
| 702 | + | |
697 | 703 | | |
698 | 704 | | |
699 | 705 | | |
| |||
815 | 821 | | |
816 | 822 | | |
817 | 823 | | |
818 | | - | |
| 824 | + | |
819 | 825 | | |
820 | 826 | | |
821 | 827 | | |
| |||
882 | 888 | | |
883 | 889 | | |
884 | 890 | | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
885 | 895 | | |
886 | 896 | | |
887 | 897 | | |
| |||
899 | 909 | | |
900 | 910 | | |
901 | 911 | | |
902 | | - | |
| 912 | + | |
903 | 913 | | |
904 | 914 | | |
905 | 915 | | |
| |||
0 commit comments