worktree: teach "repair" to fix worktree back-links to main worktree
The .git file in a linked worktree is a "gitfile" which points back to the .git/worktrees/<id> entry in the main worktree or bare repository. If a worktree's .git file is deleted or becomes corrupted or outdated, then the linked worktree won't know how to find the repository or any of its own administrative files (such as 'index', 'HEAD', etc.). An easy way for the .git file to become outdated is for the user to move the main worktree or bare repository. Although it is possible to manually update each linked worktree's .git file to reflect the new repository location, doing so requires a level of knowledge about worktree internals beyond what a user should be expected to know offhand. Therefore, teach "git worktree repair" how to repair broken or outdated worktree .git files automatically. (For this to work, the command must be invoked from within the main worktree or bare repository, or from within a worktree which has not become disconnected from the repository -- such as one which was created after the repository was moved.) Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
e8e1ff24c5
commit
bdd1f3e4da
11
worktree.h
11
worktree.h
@@ -89,6 +89,17 @@ int validate_worktree(const struct worktree *wt,
|
||||
void update_worktree_location(struct worktree *wt,
|
||||
const char *path_);
|
||||
|
||||
typedef void (* worktree_repair_fn)(int iserr, const char *path,
|
||||
const char *msg, void *cb_data);
|
||||
|
||||
/*
|
||||
* Visit each registered linked worktree and repair corruptions. For each
|
||||
* repair made or error encountered while attempting a repair, the callback
|
||||
* function, if non-NULL, is called with the path of the worktree and a
|
||||
* description of the repair or error, along with the callback user-data.
|
||||
*/
|
||||
void repair_worktrees(worktree_repair_fn, void *cb_data);
|
||||
|
||||
/*
|
||||
* Free up the memory for worktree(s)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user