worktree repair: avoid breaking unrelated .git file and gitdir - #2225
Open
yoichi wants to merge 2 commits into
Open
worktree repair: avoid breaking unrelated .git file and gitdir#2225yoichi wants to merge 2 commits into
yoichi wants to merge 2 commits into
Conversation
Remove the file reading and trimming logic from `infer_backlink()`, and instead read the .git file once in its caller, `repair_worktree_at_path()`, using `read_gitfile_raw()`. Since `read_gitfile_gently()` is replaced with `read_gitfile_raw()`, restore the logic for constructing the absolute path and replace the READ_GITFILE_ERR_NOT_A_REPO handling with a check using `is_git_directory()`. Simplify the logic for prioritizing 'inferred_backlink' over 'backlink'. Extract `get_worktree_id()` to get the worktree ID from the contents of the .git file. We are going to modify and use this function in subsequent commits. Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently,
repair_gitfile()does not verify whether the worktree IDrecorded 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 thegitdir 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.