MCPcopy Create free account
hub / github.com/git/git / repair_worktree_after_gitdir_move

Function repair_worktree_after_gitdir_move

worktree.c:720–751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

718}
719
720void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path)
721{
722 struct strbuf gitdir = STRBUF_INIT;
723 struct strbuf dotgit = STRBUF_INIT;
724 int is_relative_path;
725 char *path = NULL;
726
727 if (is_main_worktree(wt))
728 goto done;
729
730 path = repo_common_path(the_repository, "worktrees/%s/gitdir", wt->id);
731 strbuf_realpath(&gitdir, path, 1);
732
733 if (strbuf_read_file(&dotgit, gitdir.buf, 0) < 0)
734 goto done;
735
736 strbuf_rtrim(&dotgit);
737 is_relative_path = ! is_absolute_path(dotgit.buf);
738 if (is_relative_path) {
739 strbuf_insertf(&dotgit, 0, "%s/worktrees/%s/", old_path, wt->id);
740 strbuf_realpath_forgiving(&dotgit, dotgit.buf, 0);
741 }
742
743 if (!file_exists(dotgit.buf))
744 goto done;
745
746 write_worktree_linking_files(dotgit.buf, gitdir.buf, is_relative_path);
747done:
748 strbuf_release(&gitdir);
749 strbuf_release(&dotgit);
750 free(path);
751}
752
753void repair_worktrees_after_gitdir_move(const char *old_path)
754{

Callers 1

Calls 11

is_main_worktreeFunction · 0.85
repo_common_pathFunction · 0.85
strbuf_realpathFunction · 0.85
strbuf_read_fileFunction · 0.85
strbuf_rtrimFunction · 0.85
is_absolute_pathFunction · 0.85
strbuf_insertfFunction · 0.85
file_existsFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected