git
/
worktree.c
874 строки · 21.8 Кб
1#define USE_THE_REPOSITORY_VARIABLE2
3#include "git-compat-util.h"4#include "abspath.h"5#include "environment.h"6#include "gettext.h"7#include "path.h"8#include "repository.h"9#include "refs.h"10#include "setup.h"11#include "strbuf.h"12#include "worktree.h"13#include "dir.h"14#include "wt-status.h"15#include "config.h"16
17void free_worktree(struct worktree *worktree)18{
19if (!worktree)20return;21free(worktree->path);22free(worktree->id);23free(worktree->head_ref);24free(worktree->lock_reason);25free(worktree->prune_reason);26free(worktree);27}
28
29void free_worktrees(struct worktree **worktrees)30{
31int i = 0;32for (i = 0; worktrees[i]; i++)33free_worktree(worktrees[i]);34free (worktrees);35}
36
37/**
38* Update head_oid, head_ref and is_detached of the given worktree
39*/
40static void add_head_info(struct worktree *wt)41{
42int flags;43const char *target;44
45target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),46"HEAD",470,48&wt->head_oid, &flags);49if (!target)50return;51
52if (flags & REF_ISSYMREF)53wt->head_ref = xstrdup(target);54else55wt->is_detached = 1;56}
57
58static int is_current_worktree(struct worktree *wt)59{
60char *git_dir = absolute_pathdup(get_git_dir());61const char *wt_git_dir = get_worktree_git_dir(wt);62int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir));63free(git_dir);64return is_current;65}
66
67/**
68* get the main worktree
69*/
70static struct worktree *get_main_worktree(int skip_reading_head)71{
72struct worktree *worktree = NULL;73struct strbuf worktree_path = STRBUF_INIT;74
75strbuf_add_real_path(&worktree_path, get_git_common_dir());76strbuf_strip_suffix(&worktree_path, "/.git");77
78CALLOC_ARRAY(worktree, 1);79worktree->repo = the_repository;80worktree->path = strbuf_detach(&worktree_path, NULL);81/*82* NEEDSWORK: If this function is called from a secondary worktree and
83* config.worktree is present, is_bare_repository_cfg will reflect the
84* contents of config.worktree, not the contents of the main worktree.
85* This means that worktree->is_bare may be set to 0 even if the main
86* worktree is configured to be bare.
87*/
88worktree->is_bare = (is_bare_repository_cfg == 1) ||89is_bare_repository();90worktree->is_current = is_current_worktree(worktree);91if (!skip_reading_head)92add_head_info(worktree);93return worktree;94}
95
96struct worktree *get_linked_worktree(const char *id,97int skip_reading_head)98{
99struct worktree *worktree = NULL;100struct strbuf path = STRBUF_INIT;101struct strbuf worktree_path = STRBUF_INIT;102
103if (!id)104die("Missing linked worktree name");105
106strbuf_git_common_path(&path, the_repository, "worktrees/%s/gitdir", id);107if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)108/* invalid gitdir file */109goto done;110strbuf_rtrim(&worktree_path);111strbuf_strip_suffix(&worktree_path, "/.git");112
113CALLOC_ARRAY(worktree, 1);114worktree->repo = the_repository;115worktree->path = strbuf_detach(&worktree_path, NULL);116worktree->id = xstrdup(id);117worktree->is_current = is_current_worktree(worktree);118if (!skip_reading_head)119add_head_info(worktree);120
121done:122strbuf_release(&path);123strbuf_release(&worktree_path);124return worktree;125}
126
127/*
128* NEEDSWORK: This function exists so that we can look up metadata of a
129* worktree without trying to access any of its internals like the refdb. It
130* would be preferable to instead have a corruption-tolerant function for
131* retrieving worktree metadata that could be used when the worktree is known
132* to not be in a healthy state, e.g. when creating or repairing it.
133*/
134static struct worktree **get_worktrees_internal(int skip_reading_head)135{
136struct worktree **list = NULL;137struct strbuf path = STRBUF_INIT;138DIR *dir;139struct dirent *d;140int counter = 0, alloc = 2;141
142ALLOC_ARRAY(list, alloc);143
144list[counter++] = get_main_worktree(skip_reading_head);145
146strbuf_addf(&path, "%s/worktrees", get_git_common_dir());147dir = opendir(path.buf);148strbuf_release(&path);149if (dir) {150while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {151struct worktree *linked = NULL;152
153if ((linked = get_linked_worktree(d->d_name, skip_reading_head))) {154ALLOC_GROW(list, counter + 1, alloc);155list[counter++] = linked;156}157}158closedir(dir);159}160ALLOC_GROW(list, counter + 1, alloc);161list[counter] = NULL;162
163return list;164}
165
166struct worktree **get_worktrees(void)167{
168return get_worktrees_internal(0);169}
170
171const char *get_worktree_git_dir(const struct worktree *wt)172{
173if (!wt)174return get_git_dir();175else if (!wt->id)176return get_git_common_dir();177else178return git_common_path("worktrees/%s", wt->id);179}
180
181static struct worktree *find_worktree_by_suffix(struct worktree **list,182const char *suffix)183{
184struct worktree *found = NULL;185int nr_found = 0, suffixlen;186
187suffixlen = strlen(suffix);188if (!suffixlen)189return NULL;190
191for (; *list && nr_found < 2; list++) {192const char *path = (*list)->path;193int pathlen = strlen(path);194int start = pathlen - suffixlen;195
196/* suffix must start at directory boundary */197if ((!start || (start > 0 && is_dir_sep(path[start - 1]))) &&198!fspathcmp(suffix, path + start)) {199found = *list;200nr_found++;201}202}203return nr_found == 1 ? found : NULL;204}
205
206struct worktree *find_worktree(struct worktree **list,207const char *prefix,208const char *arg)209{
210struct worktree *wt;211char *to_free = NULL;212
213if ((wt = find_worktree_by_suffix(list, arg)))214return wt;215
216if (prefix)217arg = to_free = prefix_filename(prefix, arg);218wt = find_worktree_by_path(list, arg);219free(to_free);220return wt;221}
222
223struct worktree *find_worktree_by_path(struct worktree **list, const char *p)224{
225struct strbuf wt_path = STRBUF_INIT;226char *path = real_pathdup(p, 0);227
228if (!path)229return NULL;230for (; *list; list++) {231if (!strbuf_realpath(&wt_path, (*list)->path, 0))232continue;233
234if (!fspathcmp(path, wt_path.buf))235break;236}237free(path);238strbuf_release(&wt_path);239return *list;240}
241
242int is_main_worktree(const struct worktree *wt)243{
244return !wt->id;245}
246
247const char *worktree_lock_reason(struct worktree *wt)248{
249if (is_main_worktree(wt))250return NULL;251
252if (!wt->lock_reason_valid) {253struct strbuf path = STRBUF_INIT;254
255strbuf_addstr(&path, worktree_git_path(the_repository, wt, "locked"));256if (file_exists(path.buf)) {257struct strbuf lock_reason = STRBUF_INIT;258if (strbuf_read_file(&lock_reason, path.buf, 0) < 0)259die_errno(_("failed to read '%s'"), path.buf);260strbuf_trim(&lock_reason);261wt->lock_reason = strbuf_detach(&lock_reason, NULL);262} else263wt->lock_reason = NULL;264wt->lock_reason_valid = 1;265strbuf_release(&path);266}267
268return wt->lock_reason;269}
270
271const char *worktree_prune_reason(struct worktree *wt, timestamp_t expire)272{
273struct strbuf reason = STRBUF_INIT;274char *path = NULL;275
276if (is_main_worktree(wt))277return NULL;278if (wt->prune_reason_valid)279return wt->prune_reason;280
281if (should_prune_worktree(wt->id, &reason, &path, expire))282wt->prune_reason = strbuf_detach(&reason, NULL);283wt->prune_reason_valid = 1;284
285strbuf_release(&reason);286free(path);287return wt->prune_reason;288}
289
290/* convenient wrapper to deal with NULL strbuf */
291__attribute__((format (printf, 2, 3)))292static void strbuf_addf_gently(struct strbuf *buf, const char *fmt, ...)293{
294va_list params;295
296if (!buf)297return;298
299va_start(params, fmt);300strbuf_vaddf(buf, fmt, params);301va_end(params);302}
303
304int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,305unsigned flags)306{
307struct strbuf wt_path = STRBUF_INIT;308struct strbuf realpath = STRBUF_INIT;309char *path = NULL;310int err, ret = -1;311
312strbuf_addf(&wt_path, "%s/.git", wt->path);313
314if (is_main_worktree(wt)) {315if (is_directory(wt_path.buf)) {316ret = 0;317goto done;318}319/*320* Main worktree using .git file to point to the
321* repository would make it impossible to know where
322* the actual worktree is if this function is executed
323* from another worktree. No .git file support for now.
324*/
325strbuf_addf_gently(errmsg,326_("'%s' at main working tree is not the repository directory"),327wt_path.buf);328goto done;329}330
331/*332* Make sure "gitdir" file points to a real .git file and that
333* file points back here.
334*/
335if (!is_absolute_path(wt->path)) {336strbuf_addf_gently(errmsg,337_("'%s' file does not contain absolute path to the working tree location"),338git_common_path("worktrees/%s/gitdir", wt->id));339goto done;340}341
342if (flags & WT_VALIDATE_WORKTREE_MISSING_OK &&343!file_exists(wt->path)) {344ret = 0;345goto done;346}347
348if (!file_exists(wt_path.buf)) {349strbuf_addf_gently(errmsg, _("'%s' does not exist"), wt_path.buf);350goto done;351}352
353path = xstrdup_or_null(read_gitfile_gently(wt_path.buf, &err));354if (!path) {355strbuf_addf_gently(errmsg, _("'%s' is not a .git file, error code %d"),356wt_path.buf, err);357goto done;358}359
360strbuf_realpath(&realpath, git_common_path("worktrees/%s", wt->id), 1);361ret = fspathcmp(path, realpath.buf);362
363if (ret)364strbuf_addf_gently(errmsg, _("'%s' does not point back to '%s'"),365wt->path, git_common_path("worktrees/%s", wt->id));366done:367free(path);368strbuf_release(&wt_path);369strbuf_release(&realpath);370return ret;371}
372
373void update_worktree_location(struct worktree *wt, const char *path_)374{
375struct strbuf path = STRBUF_INIT;376
377if (is_main_worktree(wt))378BUG("can't relocate main worktree");379
380strbuf_realpath(&path, path_, 1);381if (fspathcmp(wt->path, path.buf)) {382write_file(git_common_path("worktrees/%s/gitdir", wt->id),383"%s/.git", path.buf);384free(wt->path);385wt->path = strbuf_detach(&path, NULL);386}387strbuf_release(&path);388}
389
390int is_worktree_being_rebased(const struct worktree *wt,391const char *target)392{
393struct wt_status_state state;394int found_rebase;395
396memset(&state, 0, sizeof(state));397found_rebase = wt_status_check_rebase(wt, &state) &&398(state.rebase_in_progress ||399state.rebase_interactive_in_progress) &&400state.branch &&401skip_prefix(target, "refs/heads/", &target) &&402!strcmp(state.branch, target);403wt_status_state_free_buffers(&state);404return found_rebase;405}
406
407int is_worktree_being_bisected(const struct worktree *wt,408const char *target)409{
410struct wt_status_state state;411int found_bisect;412
413memset(&state, 0, sizeof(state));414found_bisect = wt_status_check_bisect(wt, &state) &&415state.bisecting_from &&416skip_prefix(target, "refs/heads/", &target) &&417!strcmp(state.bisecting_from, target);418wt_status_state_free_buffers(&state);419return found_bisect;420}
421
422/*
423* note: this function should be able to detect shared symref even if
424* HEAD is temporarily detached (e.g. in the middle of rebase or
425* bisect). New commands that do similar things should update this
426* function as well.
427*/
428int is_shared_symref(const struct worktree *wt, const char *symref,429const char *target)430{
431const char *symref_target;432struct ref_store *refs;433int flags;434
435if (wt->is_bare)436return 0;437
438if (wt->is_detached && !strcmp(symref, "HEAD")) {439if (is_worktree_being_rebased(wt, target))440return 1;441if (is_worktree_being_bisected(wt, target))442return 1;443}444
445refs = get_worktree_ref_store(wt);446symref_target = refs_resolve_ref_unsafe(refs, symref, 0,447NULL, &flags);448if ((flags & REF_ISSYMREF) &&449symref_target && !strcmp(symref_target, target))450return 1;451
452return 0;453}
454
455const struct worktree *find_shared_symref(struct worktree **worktrees,456const char *symref,457const char *target)458{
459
460for (int i = 0; worktrees[i]; i++)461if (is_shared_symref(worktrees[i], symref, target))462return worktrees[i];463
464return NULL;465}
466
467int submodule_uses_worktrees(const char *path)468{
469char *submodule_gitdir;470struct strbuf sb = STRBUF_INIT, err = STRBUF_INIT;471DIR *dir;472struct dirent *d;473int ret = 0;474struct repository_format format = REPOSITORY_FORMAT_INIT;475
476submodule_gitdir = git_pathdup_submodule(path, "%s", "");477if (!submodule_gitdir)478return 0;479
480/* The env would be set for the superproject. */481get_common_dir_noenv(&sb, submodule_gitdir);482free(submodule_gitdir);483
484strbuf_addstr(&sb, "/config");485read_repository_format(&format, sb.buf);486if (verify_repository_format(&format, &err)) {487strbuf_release(&err);488strbuf_release(&sb);489clear_repository_format(&format);490return 1;491}492clear_repository_format(&format);493strbuf_release(&err);494
495/* Replace config by worktrees. */496strbuf_setlen(&sb, sb.len - strlen("config"));497strbuf_addstr(&sb, "worktrees");498
499/* See if there is any file inside the worktrees directory. */500dir = opendir(sb.buf);501strbuf_release(&sb);502
503if (!dir)504return 0;505
506d = readdir_skip_dot_and_dotdot(dir);507if (d)508ret = 1;509closedir(dir);510return ret;511}
512
513void strbuf_worktree_ref(const struct worktree *wt,514struct strbuf *sb,515const char *refname)516{
517if (parse_worktree_ref(refname, NULL, NULL, NULL) ==518REF_WORKTREE_CURRENT &&519wt && !wt->is_current) {520if (is_main_worktree(wt))521strbuf_addstr(sb, "main-worktree/");522else523strbuf_addf(sb, "worktrees/%s/", wt->id);524}525strbuf_addstr(sb, refname);526}
527
528int other_head_refs(each_ref_fn fn, void *cb_data)529{
530struct worktree **worktrees, **p;531struct strbuf refname = STRBUF_INIT;532int ret = 0;533
534worktrees = get_worktrees();535for (p = worktrees; *p; p++) {536struct worktree *wt = *p;537struct object_id oid;538int flag;539
540if (wt->is_current)541continue;542
543strbuf_reset(&refname);544strbuf_worktree_ref(wt, &refname, "HEAD");545if (refs_resolve_ref_unsafe(get_main_ref_store(the_repository),546refname.buf,547RESOLVE_REF_READING,548&oid, &flag))549ret = fn(refname.buf, NULL, &oid, flag, cb_data);550if (ret)551break;552}553free_worktrees(worktrees);554strbuf_release(&refname);555return ret;556}
557
558/*
559* Repair worktree's /path/to/worktree/.git file if missing, corrupt, or not
560* pointing at <repo>/worktrees/<id>.
561*/
562static void repair_gitfile(struct worktree *wt,563worktree_repair_fn fn, void *cb_data)564{
565struct strbuf dotgit = STRBUF_INIT;566struct strbuf repo = STRBUF_INIT;567char *backlink;568const char *repair = NULL;569int err;570
571/* missing worktree can't be repaired */572if (!file_exists(wt->path))573return;574
575if (!is_directory(wt->path)) {576fn(1, wt->path, _("not a directory"), cb_data);577return;578}579
580strbuf_realpath(&repo, git_common_path("worktrees/%s", wt->id), 1);581strbuf_addf(&dotgit, "%s/.git", wt->path);582backlink = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err));583
584if (err == READ_GITFILE_ERR_NOT_A_FILE)585fn(1, wt->path, _(".git is not a file"), cb_data);586else if (err)587repair = _(".git file broken");588else if (fspathcmp(backlink, repo.buf))589repair = _(".git file incorrect");590
591if (repair) {592fn(0, wt->path, repair, cb_data);593write_file(dotgit.buf, "gitdir: %s", repo.buf);594}595
596free(backlink);597strbuf_release(&repo);598strbuf_release(&dotgit);599}
600
601static void repair_noop(int iserr UNUSED,602const char *path UNUSED,603const char *msg UNUSED,604void *cb_data UNUSED)605{
606/* nothing */607}
608
609void repair_worktrees(worktree_repair_fn fn, void *cb_data)610{
611struct worktree **worktrees = get_worktrees_internal(1);612struct worktree **wt = worktrees + 1; /* +1 skips main worktree */613
614if (!fn)615fn = repair_noop;616for (; *wt; wt++)617repair_gitfile(*wt, fn, cb_data);618free_worktrees(worktrees);619}
620
621static int is_main_worktree_path(const char *path)622{
623struct strbuf target = STRBUF_INIT;624struct strbuf maindir = STRBUF_INIT;625int cmp;626
627strbuf_add_real_path(&target, path);628strbuf_strip_suffix(&target, "/.git");629strbuf_add_real_path(&maindir, get_git_common_dir());630strbuf_strip_suffix(&maindir, "/.git");631cmp = fspathcmp(maindir.buf, target.buf);632
633strbuf_release(&maindir);634strbuf_release(&target);635return !cmp;636}
637
638/*
639* If both the main worktree and linked worktree have been moved, then the
640* gitfile /path/to/worktree/.git won't point into the repository, thus we
641* won't know which <repo>/worktrees/<id>/gitdir to repair. However, we may
642* be able to infer the gitdir by manually reading /path/to/worktree/.git,
643* extracting the <id>, and checking if <repo>/worktrees/<id> exists.
644*/
645static char *infer_backlink(const char *gitfile)646{
647struct strbuf actual = STRBUF_INIT;648struct strbuf inferred = STRBUF_INIT;649const char *id;650
651if (strbuf_read_file(&actual, gitfile, 0) < 0)652goto error;653if (!starts_with(actual.buf, "gitdir:"))654goto error;655if (!(id = find_last_dir_sep(actual.buf)))656goto error;657strbuf_trim(&actual);658id++; /* advance past '/' to point at <id> */659if (!*id)660goto error;661strbuf_git_common_path(&inferred, the_repository, "worktrees/%s", id);662if (!is_directory(inferred.buf))663goto error;664
665strbuf_release(&actual);666return strbuf_detach(&inferred, NULL);667
668error:669strbuf_release(&actual);670strbuf_release(&inferred);671return NULL;672}
673
674/*
675* Repair <repo>/worktrees/<id>/gitdir if missing, corrupt, or not pointing at
676* the worktree's path.
677*/
678void repair_worktree_at_path(const char *path,679worktree_repair_fn fn, void *cb_data)680{
681struct strbuf dotgit = STRBUF_INIT;682struct strbuf realdotgit = STRBUF_INIT;683struct strbuf gitdir = STRBUF_INIT;684struct strbuf olddotgit = STRBUF_INIT;685char *backlink = NULL;686const char *repair = NULL;687int err;688
689if (!fn)690fn = repair_noop;691
692if (is_main_worktree_path(path))693goto done;694
695strbuf_addf(&dotgit, "%s/.git", path);696if (!strbuf_realpath(&realdotgit, dotgit.buf, 0)) {697fn(1, path, _("not a valid path"), cb_data);698goto done;699}700
701backlink = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));702if (err == READ_GITFILE_ERR_NOT_A_FILE) {703fn(1, realdotgit.buf, _("unable to locate repository; .git is not a file"), cb_data);704goto done;705} else if (err == READ_GITFILE_ERR_NOT_A_REPO) {706if (!(backlink = infer_backlink(realdotgit.buf))) {707fn(1, realdotgit.buf, _("unable to locate repository; .git file does not reference a repository"), cb_data);708goto done;709}710} else if (err) {711fn(1, realdotgit.buf, _("unable to locate repository; .git file broken"), cb_data);712goto done;713}714
715strbuf_addf(&gitdir, "%s/gitdir", backlink);716if (strbuf_read_file(&olddotgit, gitdir.buf, 0) < 0)717repair = _("gitdir unreadable");718else {719strbuf_rtrim(&olddotgit);720if (fspathcmp(olddotgit.buf, realdotgit.buf))721repair = _("gitdir incorrect");722}723
724if (repair) {725fn(0, gitdir.buf, repair, cb_data);726write_file(gitdir.buf, "%s", realdotgit.buf);727}728done:729free(backlink);730strbuf_release(&olddotgit);731strbuf_release(&gitdir);732strbuf_release(&realdotgit);733strbuf_release(&dotgit);734}
735
736int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath, timestamp_t expire)737{
738struct stat st;739char *path;740int fd;741size_t len;742ssize_t read_result;743
744*wtpath = NULL;745if (!is_directory(git_path("worktrees/%s", id))) {746strbuf_addstr(reason, _("not a valid directory"));747return 1;748}749if (file_exists(git_path("worktrees/%s/locked", id)))750return 0;751if (stat(git_path("worktrees/%s/gitdir", id), &st)) {752strbuf_addstr(reason, _("gitdir file does not exist"));753return 1;754}755fd = open(git_path("worktrees/%s/gitdir", id), O_RDONLY);756if (fd < 0) {757strbuf_addf(reason, _("unable to read gitdir file (%s)"),758strerror(errno));759return 1;760}761len = xsize_t(st.st_size);762path = xmallocz(len);763
764read_result = read_in_full(fd, path, len);765if (read_result < 0) {766strbuf_addf(reason, _("unable to read gitdir file (%s)"),767strerror(errno));768close(fd);769free(path);770return 1;771}772close(fd);773
774if (read_result != len) {775strbuf_addf(reason,776_("short read (expected %"PRIuMAX" bytes, read %"PRIuMAX")"),777(uintmax_t)len, (uintmax_t)read_result);778free(path);779return 1;780}781while (len && (path[len - 1] == '\n' || path[len - 1] == '\r'))782len--;783if (!len) {784strbuf_addstr(reason, _("invalid gitdir file"));785free(path);786return 1;787}788path[len] = '\0';789if (!file_exists(path)) {790if (stat(git_path("worktrees/%s/index", id), &st) ||791st.st_mtime <= expire) {792strbuf_addstr(reason, _("gitdir file points to non-existent location"));793free(path);794return 1;795} else {796*wtpath = path;797return 0;798}799}800*wtpath = path;801return 0;802}
803
804static int move_config_setting(const char *key, const char *value,805const char *from_file, const char *to_file)806{
807if (git_config_set_in_file_gently(to_file, key, NULL, value))808return error(_("unable to set %s in '%s'"), key, to_file);809if (git_config_set_in_file_gently(from_file, key, NULL, NULL))810return error(_("unable to unset %s in '%s'"), key, from_file);811return 0;812}
813
814int init_worktree_config(struct repository *r)815{
816int res = 0;817int bare = 0;818struct config_set cs = { { 0 } };819const char *core_worktree;820char *common_config_file;821char *main_worktree_file;822
823/*824* If the extension is already enabled, then we can skip the
825* upgrade process.
826*/
827if (r->repository_format_worktree_config)828return 0;829if ((res = git_config_set_gently("extensions.worktreeConfig", "true")))830return error(_("failed to set extensions.worktreeConfig setting"));831
832common_config_file = xstrfmt("%s/config", r->commondir);833main_worktree_file = xstrfmt("%s/config.worktree", r->commondir);834
835git_configset_init(&cs);836git_configset_add_file(&cs, common_config_file);837
838/*839* If core.bare is true in the common config file, then we need to
840* move it to the main worktree's config file or it will break all
841* worktrees. If it is false, then leave it in place because it
842* _could_ be negating a global core.bare=true.
843*/
844if (!git_configset_get_bool(&cs, "core.bare", &bare) && bare) {845if ((res = move_config_setting("core.bare", "true",846common_config_file,847main_worktree_file)))848goto cleanup;849}850/*851* If core.worktree is set, then the main worktree is located
852* somewhere different than the parent of the common Git dir.
853* Relocate that value to avoid breaking all worktrees with this
854* upgrade to worktree config.
855*/
856if (!git_configset_get_value(&cs, "core.worktree", &core_worktree, NULL)) {857if ((res = move_config_setting("core.worktree", core_worktree,858common_config_file,859main_worktree_file)))860goto cleanup;861}862
863/*864* Ensure that we use worktree config for the remaining lifetime
865* of the current process.
866*/
867r->repository_format_worktree_config = 1;868
869cleanup:870git_configset_clear(&cs);871free(common_config_file);872free(main_worktree_file);873return res;874}
875