]> git.ipfire.org Git - thirdparty/git.git/blob - branch.c
branch: remove negative exit code
[thirdparty/git.git] / branch.c
1 #include "git-compat-util.h"
2 #include "cache.h"
3 #include "config.h"
4 #include "branch.h"
5 #include "refs.h"
6 #include "refspec.h"
7 #include "remote.h"
8 #include "sequencer.h"
9 #include "commit.h"
10 #include "worktree.h"
11 #include "submodule-config.h"
12 #include "run-command.h"
13
14 struct tracking {
15 struct refspec_item spec;
16 struct string_list *srcs;
17 const char *remote;
18 int matches;
19 };
20
21 static int find_tracked_branch(struct remote *remote, void *priv)
22 {
23 struct tracking *tracking = priv;
24
25 if (!remote_find_tracking(remote, &tracking->spec)) {
26 if (++tracking->matches == 1) {
27 string_list_append(tracking->srcs, tracking->spec.src);
28 tracking->remote = remote->name;
29 } else {
30 free(tracking->spec.src);
31 string_list_clear(tracking->srcs, 0);
32 }
33 tracking->spec.src = NULL;
34 }
35
36 return 0;
37 }
38
39 static int should_setup_rebase(const char *origin)
40 {
41 switch (autorebase) {
42 case AUTOREBASE_NEVER:
43 return 0;
44 case AUTOREBASE_LOCAL:
45 return origin == NULL;
46 case AUTOREBASE_REMOTE:
47 return origin != NULL;
48 case AUTOREBASE_ALWAYS:
49 return 1;
50 }
51 return 0;
52 }
53
54 /**
55 * Install upstream tracking configuration for a branch; specifically, add
56 * `branch.<name>.remote` and `branch.<name>.merge` entries.
57 *
58 * `flag` contains integer flags for options; currently only
59 * BRANCH_CONFIG_VERBOSE is checked.
60 *
61 * `local` is the name of the branch whose configuration we're installing.
62 *
63 * `origin` is the name of the remote owning the upstream branches. NULL means
64 * the upstream branches are local to this repo.
65 *
66 * `remotes` is a list of refs that are upstream of local
67 */
68 static int install_branch_config_multiple_remotes(int flag, const char *local,
69 const char *origin, struct string_list *remotes)
70 {
71 const char *shortname = NULL;
72 struct strbuf key = STRBUF_INIT;
73 struct string_list_item *item;
74 int rebasing = should_setup_rebase(origin);
75
76 if (!remotes->nr)
77 BUG("must provide at least one remote for branch config");
78 if (rebasing && remotes->nr > 1)
79 die(_("cannot inherit upstream tracking configuration of "
80 "multiple refs when rebasing is requested"));
81
82 /*
83 * If the new branch is trying to track itself, something has gone
84 * wrong. Warn the user and don't proceed any further.
85 */
86 if (!origin)
87 for_each_string_list_item(item, remotes)
88 if (skip_prefix(item->string, "refs/heads/", &shortname)
89 && !strcmp(local, shortname)) {
90 warning(_("not setting branch '%s' as its own upstream."),
91 local);
92 return 0;
93 }
94
95 strbuf_addf(&key, "branch.%s.remote", local);
96 if (git_config_set_gently(key.buf, origin ? origin : ".") < 0)
97 goto out_err;
98
99 strbuf_reset(&key);
100 strbuf_addf(&key, "branch.%s.merge", local);
101 /*
102 * We want to overwrite any existing config with all the branches in
103 * "remotes". Override any existing config, then write our branches. If
104 * more than one is provided, use CONFIG_REGEX_NONE to preserve what
105 * we've written so far.
106 */
107 if (git_config_set_gently(key.buf, NULL) < 0)
108 goto out_err;
109 for_each_string_list_item(item, remotes)
110 if (git_config_set_multivar_gently(key.buf, item->string, CONFIG_REGEX_NONE, 0) < 0)
111 goto out_err;
112
113 if (rebasing) {
114 strbuf_reset(&key);
115 strbuf_addf(&key, "branch.%s.rebase", local);
116 if (git_config_set_gently(key.buf, "true") < 0)
117 goto out_err;
118 }
119 strbuf_release(&key);
120
121 if (flag & BRANCH_CONFIG_VERBOSE) {
122 struct strbuf tmp_ref_name = STRBUF_INIT;
123 struct string_list friendly_ref_names = STRING_LIST_INIT_DUP;
124
125 for_each_string_list_item(item, remotes) {
126 shortname = item->string;
127 skip_prefix(shortname, "refs/heads/", &shortname);
128 if (origin) {
129 strbuf_addf(&tmp_ref_name, "%s/%s",
130 origin, shortname);
131 string_list_append_nodup(
132 &friendly_ref_names,
133 strbuf_detach(&tmp_ref_name, NULL));
134 } else {
135 string_list_append(
136 &friendly_ref_names, shortname);
137 }
138 }
139
140 if (remotes->nr == 1) {
141 /*
142 * Rebasing is only allowed in the case of a single
143 * upstream branch.
144 */
145 printf_ln(rebasing ?
146 _("branch '%s' set up to track '%s' by rebasing.") :
147 _("branch '%s' set up to track '%s'."),
148 local, friendly_ref_names.items[0].string);
149 } else {
150 printf_ln(_("branch '%s' set up to track:"), local);
151 for_each_string_list_item(item, &friendly_ref_names)
152 printf_ln(" %s", item->string);
153 }
154
155 string_list_clear(&friendly_ref_names, 0);
156 }
157
158 return 0;
159
160 out_err:
161 strbuf_release(&key);
162 error(_("Unable to write upstream branch configuration"));
163
164 advise(_("\nAfter fixing the error cause you may try to fix up\n"
165 "the remote tracking information by invoking:"));
166 if (remotes->nr == 1)
167 advise(" git branch --set-upstream-to=%s%s%s",
168 origin ? origin : "",
169 origin ? "/" : "",
170 remotes->items[0].string);
171 else {
172 advise(" git config --add branch.\"%s\".remote %s",
173 local, origin ? origin : ".");
174 for_each_string_list_item(item, remotes)
175 advise(" git config --add branch.\"%s\".merge %s",
176 local, item->string);
177 }
178
179 return -1;
180 }
181
182 int install_branch_config(int flag, const char *local, const char *origin,
183 const char *remote)
184 {
185 int ret;
186 struct string_list remotes = STRING_LIST_INIT_DUP;
187
188 string_list_append(&remotes, remote);
189 ret = install_branch_config_multiple_remotes(flag, local, origin, &remotes);
190 string_list_clear(&remotes, 0);
191 return ret;
192 }
193
194 static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
195 {
196 const char *bare_ref;
197 struct branch *branch;
198 int i;
199
200 bare_ref = orig_ref;
201 skip_prefix(orig_ref, "refs/heads/", &bare_ref);
202
203 branch = branch_get(bare_ref);
204 if (!branch->remote_name) {
205 warning(_("asked to inherit tracking from '%s', but no remote is set"),
206 bare_ref);
207 return -1;
208 }
209
210 if (branch->merge_nr < 1 || !branch->merge_name || !branch->merge_name[0]) {
211 warning(_("asked to inherit tracking from '%s', but no merge configuration is set"),
212 bare_ref);
213 return -1;
214 }
215
216 tracking->remote = xstrdup(branch->remote_name);
217 for (i = 0; i < branch->merge_nr; i++)
218 string_list_append(tracking->srcs, branch->merge_name[i]);
219 return 0;
220 }
221
222 /*
223 * Used internally to set the branch.<new_ref>.{remote,merge} config
224 * settings so that branch 'new_ref' tracks 'orig_ref'. Unlike
225 * dwim_and_setup_tracking(), this does not do DWIM, i.e. "origin/main"
226 * will not be expanded to "refs/remotes/origin/main", so it is not safe
227 * for 'orig_ref' to be raw user input.
228 */
229 static void setup_tracking(const char *new_ref, const char *orig_ref,
230 enum branch_track track, int quiet)
231 {
232 struct tracking tracking;
233 struct string_list tracking_srcs = STRING_LIST_INIT_DUP;
234 int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
235
236 if (!track)
237 BUG("asked to set up tracking, but tracking is disallowed");
238
239 memset(&tracking, 0, sizeof(tracking));
240 tracking.spec.dst = (char *)orig_ref;
241 tracking.srcs = &tracking_srcs;
242 if (track != BRANCH_TRACK_INHERIT)
243 for_each_remote(find_tracked_branch, &tracking);
244 else if (inherit_tracking(&tracking, orig_ref))
245 goto cleanup;
246
247 if (!tracking.matches)
248 switch (track) {
249 case BRANCH_TRACK_ALWAYS:
250 case BRANCH_TRACK_EXPLICIT:
251 case BRANCH_TRACK_OVERRIDE:
252 case BRANCH_TRACK_INHERIT:
253 break;
254 default:
255 goto cleanup;
256 }
257
258 if (tracking.matches > 1)
259 die(_("Not tracking: ambiguous information for ref %s"),
260 orig_ref);
261
262 if (tracking.srcs->nr < 1)
263 string_list_append(tracking.srcs, orig_ref);
264 if (install_branch_config_multiple_remotes(config_flags, new_ref,
265 tracking.remote, tracking.srcs) < 0)
266 exit(1);
267
268 cleanup:
269 string_list_clear(&tracking_srcs, 0);
270 }
271
272 int read_branch_desc(struct strbuf *buf, const char *branch_name)
273 {
274 char *v = NULL;
275 struct strbuf name = STRBUF_INIT;
276 strbuf_addf(&name, "branch.%s.description", branch_name);
277 if (git_config_get_string(name.buf, &v)) {
278 strbuf_release(&name);
279 return -1;
280 }
281 strbuf_addstr(buf, v);
282 free(v);
283 strbuf_release(&name);
284 return 0;
285 }
286
287 /*
288 * Check if 'name' can be a valid name for a branch; die otherwise.
289 * Return 1 if the named branch already exists; return 0 otherwise.
290 * Fill ref with the full refname for the branch.
291 */
292 int validate_branchname(const char *name, struct strbuf *ref)
293 {
294 if (strbuf_check_branch_ref(ref, name))
295 die(_("'%s' is not a valid branch name."), name);
296
297 return ref_exists(ref->buf);
298 }
299
300 /*
301 * Check if a branch 'name' can be created as a new branch; die otherwise.
302 * 'force' can be used when it is OK for the named branch already exists.
303 * Return 1 if the named branch already exists; return 0 otherwise.
304 * Fill ref with the full refname for the branch.
305 */
306 int validate_new_branchname(const char *name, struct strbuf *ref, int force)
307 {
308 const char *head;
309
310 if (!validate_branchname(name, ref))
311 return 0;
312
313 if (!force)
314 die(_("A branch named '%s' already exists."),
315 ref->buf + strlen("refs/heads/"));
316
317 head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
318 if (!is_bare_repository() && head && !strcmp(head, ref->buf))
319 die(_("Cannot force update the current branch."));
320
321 return 1;
322 }
323
324 static int check_tracking_branch(struct remote *remote, void *cb_data)
325 {
326 char *tracking_branch = cb_data;
327 struct refspec_item query;
328 memset(&query, 0, sizeof(struct refspec_item));
329 query.dst = tracking_branch;
330 return !remote_find_tracking(remote, &query);
331 }
332
333 static int validate_remote_tracking_branch(char *ref)
334 {
335 return !for_each_remote(check_tracking_branch, ref);
336 }
337
338 static const char upstream_not_branch[] =
339 N_("Cannot setup tracking information; starting point '%s' is not a branch.");
340 static const char upstream_missing[] =
341 N_("the requested upstream branch '%s' does not exist");
342 static const char upstream_advice[] =
343 N_("\n"
344 "If you are planning on basing your work on an upstream\n"
345 "branch that already exists at the remote, you may need to\n"
346 "run \"git fetch\" to retrieve it.\n"
347 "\n"
348 "If you are planning to push out a new local branch that\n"
349 "will track its remote counterpart, you may want to use\n"
350 "\"git push -u\" to set the upstream config as you push.");
351
352 /**
353 * DWIMs a user-provided ref to determine the starting point for a
354 * branch and validates it, where:
355 *
356 * - r is the repository to validate the branch for
357 *
358 * - start_name is the ref that we would like to test. This is
359 * expanded with DWIM and assigned to out_real_ref.
360 *
361 * - track is the tracking mode of the new branch. If tracking is
362 * explicitly requested, start_name must be a branch (because
363 * otherwise start_name cannot be tracked)
364 *
365 * - out_oid is an out parameter containing the object_id of start_name
366 *
367 * - out_real_ref is an out parameter containing the full, 'real' form
368 * of start_name e.g. refs/heads/main instead of main
369 *
370 */
371 static void dwim_branch_start(struct repository *r, const char *start_name,
372 enum branch_track track, char **out_real_ref,
373 struct object_id *out_oid)
374 {
375 struct commit *commit;
376 struct object_id oid;
377 char *real_ref;
378 int explicit_tracking = 0;
379
380 if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE)
381 explicit_tracking = 1;
382
383 real_ref = NULL;
384 if (get_oid_mb(start_name, &oid)) {
385 if (explicit_tracking) {
386 if (advice_enabled(ADVICE_SET_UPSTREAM_FAILURE)) {
387 int code = die_message(_(upstream_missing),
388 start_name);
389 advise(_(upstream_advice));
390 exit(code);
391 }
392 die(_(upstream_missing), start_name);
393 }
394 die(_("Not a valid object name: '%s'."), start_name);
395 }
396
397 switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref, 0)) {
398 case 0:
399 /* Not branching from any existing branch */
400 if (explicit_tracking)
401 die(_(upstream_not_branch), start_name);
402 break;
403 case 1:
404 /* Unique completion -- good, only if it is a real branch */
405 if (!starts_with(real_ref, "refs/heads/") &&
406 validate_remote_tracking_branch(real_ref)) {
407 if (explicit_tracking)
408 die(_(upstream_not_branch), start_name);
409 else
410 FREE_AND_NULL(real_ref);
411 }
412 break;
413 default:
414 die(_("Ambiguous object name: '%s'."), start_name);
415 break;
416 }
417
418 if ((commit = lookup_commit_reference(r, &oid)) == NULL)
419 die(_("Not a valid branch point: '%s'."), start_name);
420 if (out_real_ref) {
421 *out_real_ref = real_ref;
422 real_ref = NULL;
423 }
424 if (out_oid)
425 oidcpy(out_oid, &commit->object.oid);
426
427 FREE_AND_NULL(real_ref);
428 }
429
430 void create_branch(struct repository *r,
431 const char *name, const char *start_name,
432 int force, int clobber_head_ok, int reflog,
433 int quiet, enum branch_track track, int dry_run)
434 {
435 struct object_id oid;
436 char *real_ref;
437 struct strbuf ref = STRBUF_INIT;
438 int forcing = 0;
439 struct ref_transaction *transaction;
440 struct strbuf err = STRBUF_INIT;
441 char *msg;
442
443 if (track == BRANCH_TRACK_OVERRIDE)
444 BUG("'track' cannot be BRANCH_TRACK_OVERRIDE. Did you mean to call dwim_and_setup_tracking()?");
445 if (clobber_head_ok && !force)
446 BUG("'clobber_head_ok' can only be used with 'force'");
447
448 if (clobber_head_ok ?
449 validate_branchname(name, &ref) :
450 validate_new_branchname(name, &ref, force)) {
451 forcing = 1;
452 }
453
454 dwim_branch_start(r, start_name, track, &real_ref, &oid);
455 if (dry_run)
456 goto cleanup;
457
458 if (reflog)
459 log_all_ref_updates = LOG_REFS_NORMAL;
460
461 if (forcing)
462 msg = xstrfmt("branch: Reset to %s", start_name);
463 else
464 msg = xstrfmt("branch: Created from %s", start_name);
465 transaction = ref_transaction_begin(&err);
466 if (!transaction ||
467 ref_transaction_update(transaction, ref.buf,
468 &oid, forcing ? NULL : null_oid(),
469 0, msg, &err) ||
470 ref_transaction_commit(transaction, &err))
471 die("%s", err.buf);
472 ref_transaction_free(transaction);
473 strbuf_release(&err);
474 free(msg);
475
476 if (real_ref && track)
477 setup_tracking(ref.buf + 11, real_ref, track, quiet);
478
479 cleanup:
480 strbuf_release(&ref);
481 free(real_ref);
482 }
483
484 void dwim_and_setup_tracking(struct repository *r, const char *new_ref,
485 const char *orig_ref, enum branch_track track,
486 int quiet)
487 {
488 char *real_orig_ref;
489 dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL);
490 setup_tracking(new_ref, real_orig_ref, track, quiet);
491 }
492
493 /**
494 * Creates a branch in a submodule by calling
495 * create_branches_recursively() in a child process. The child process
496 * is necessary because install_branch_config_multiple_remotes() (which
497 * is called by setup_tracking()) does not support writing configs to
498 * submodules.
499 */
500 static int submodule_create_branch(struct repository *r,
501 const struct submodule *submodule,
502 const char *name, const char *start_oid,
503 const char *tracking_name, int force,
504 int reflog, int quiet,
505 enum branch_track track, int dry_run)
506 {
507 int ret = 0;
508 struct child_process child = CHILD_PROCESS_INIT;
509 struct strbuf child_err = STRBUF_INIT;
510 struct strbuf out_buf = STRBUF_INIT;
511 char *out_prefix = xstrfmt("submodule '%s': ", submodule->name);
512 child.git_cmd = 1;
513 child.err = -1;
514 child.stdout_to_stderr = 1;
515
516 prepare_other_repo_env(&child.env_array, r->gitdir);
517 /*
518 * submodule_create_branch() is indirectly invoked by "git
519 * branch", but we cannot invoke "git branch" in the child
520 * process. "git branch" accepts a branch name and start point,
521 * where the start point is assumed to provide both the OID
522 * (start_oid) and the branch to use for tracking
523 * (tracking_name). But when recursing through submodules,
524 * start_oid and tracking name need to be specified separately
525 * (see create_branches_recursively()).
526 */
527 strvec_pushl(&child.args, "submodule--helper", "create-branch", NULL);
528 if (dry_run)
529 strvec_push(&child.args, "--dry-run");
530 if (force)
531 strvec_push(&child.args, "--force");
532 if (quiet)
533 strvec_push(&child.args, "--quiet");
534 if (reflog)
535 strvec_push(&child.args, "--create-reflog");
536
537 switch (track) {
538 case BRANCH_TRACK_NEVER:
539 strvec_push(&child.args, "--no-track");
540 break;
541 case BRANCH_TRACK_ALWAYS:
542 case BRANCH_TRACK_EXPLICIT:
543 strvec_push(&child.args, "--track=direct");
544 break;
545 case BRANCH_TRACK_OVERRIDE:
546 BUG("BRANCH_TRACK_OVERRIDE cannot be used when creating a branch.");
547 break;
548 case BRANCH_TRACK_INHERIT:
549 strvec_push(&child.args, "--track=inherit");
550 break;
551 case BRANCH_TRACK_UNSPECIFIED:
552 /* Default for "git checkout". No need to pass --track. */
553 case BRANCH_TRACK_REMOTE:
554 /* Default for "git branch". No need to pass --track. */
555 break;
556 }
557
558 strvec_pushl(&child.args, name, start_oid, tracking_name, NULL);
559
560 if ((ret = start_command(&child)))
561 return ret;
562 ret = finish_command(&child);
563 strbuf_read(&child_err, child.err, 0);
564 strbuf_add_lines(&out_buf, out_prefix, child_err.buf, child_err.len);
565
566 if (ret)
567 fprintf(stderr, "%s", out_buf.buf);
568 else
569 printf("%s", out_buf.buf);
570
571 strbuf_release(&child_err);
572 strbuf_release(&out_buf);
573 return ret;
574 }
575
576 void create_branches_recursively(struct repository *r, const char *name,
577 const char *start_commitish,
578 const char *tracking_name, int force,
579 int reflog, int quiet, enum branch_track track,
580 int dry_run)
581 {
582 int i = 0;
583 char *branch_point = NULL;
584 struct object_id super_oid;
585 struct submodule_entry_list submodule_entry_list;
586
587 /* Perform dwim on start_commitish to get super_oid and branch_point. */
588 dwim_branch_start(r, start_commitish, BRANCH_TRACK_NEVER,
589 &branch_point, &super_oid);
590
591 /*
592 * If we were not given an explicit name to track, then assume we are at
593 * the top level and, just like the non-recursive case, the tracking
594 * name is the branch point.
595 */
596 if (!tracking_name)
597 tracking_name = branch_point;
598
599 submodules_of_tree(r, &super_oid, &submodule_entry_list);
600 /*
601 * Before creating any branches, first check that the branch can
602 * be created in every submodule.
603 */
604 for (i = 0; i < submodule_entry_list.entry_nr; i++) {
605 if (submodule_entry_list.entries[i].repo == NULL) {
606 int code = die_message(
607 _("submodule '%s': unable to find submodule"),
608 submodule_entry_list.entries[i].submodule->name);
609 if (advice_enabled(ADVICE_SUBMODULES_NOT_UPDATED))
610 advise(_("You may try updating the submodules using 'git checkout %s && git submodule update --init'"),
611 start_commitish);
612 exit(code);
613 }
614
615 if (submodule_create_branch(
616 submodule_entry_list.entries[i].repo,
617 submodule_entry_list.entries[i].submodule, name,
618 oid_to_hex(&submodule_entry_list.entries[i]
619 .name_entry->oid),
620 tracking_name, force, reflog, quiet, track, 1))
621 die(_("submodule '%s': cannot create branch '%s'"),
622 submodule_entry_list.entries[i].submodule->name,
623 name);
624 }
625
626 create_branch(the_repository, name, start_commitish, force, 0, reflog, quiet,
627 BRANCH_TRACK_NEVER, dry_run);
628 if (dry_run)
629 return;
630 /*
631 * NEEDSWORK If tracking was set up in the superproject but not the
632 * submodule, users might expect "git branch --recurse-submodules" to
633 * fail or give a warning, but this is not yet implemented because it is
634 * tedious to determine whether or not tracking was set up in the
635 * superproject.
636 */
637 if (track)
638 setup_tracking(name, tracking_name, track, quiet);
639
640 for (i = 0; i < submodule_entry_list.entry_nr; i++) {
641 if (submodule_create_branch(
642 submodule_entry_list.entries[i].repo,
643 submodule_entry_list.entries[i].submodule, name,
644 oid_to_hex(&submodule_entry_list.entries[i]
645 .name_entry->oid),
646 tracking_name, force, reflog, quiet, track, 0))
647 die(_("submodule '%s': cannot create branch '%s'"),
648 submodule_entry_list.entries[i].submodule->name,
649 name);
650 repo_clear(submodule_entry_list.entries[i].repo);
651 }
652 }
653
654 void remove_merge_branch_state(struct repository *r)
655 {
656 unlink(git_path_merge_head(r));
657 unlink(git_path_merge_rr(r));
658 unlink(git_path_merge_msg(r));
659 unlink(git_path_merge_mode(r));
660 unlink(git_path_auto_merge(r));
661 save_autostash(git_path_merge_autostash(r));
662 }
663
664 void remove_branch_state(struct repository *r, int verbose)
665 {
666 sequencer_post_commit_cleanup(r, verbose);
667 unlink(git_path_squash_msg(r));
668 remove_merge_branch_state(r);
669 }
670
671 void die_if_checked_out(const char *branch, int ignore_current_worktree)
672 {
673 const struct worktree *wt;
674
675 wt = find_shared_symref("HEAD", branch);
676 if (!wt || (ignore_current_worktree && wt->is_current))
677 return;
678 skip_prefix(branch, "refs/heads/", &branch);
679 die(_("'%s' is already checked out at '%s'"),
680 branch, wt->path);
681 }
682
683 int replace_each_worktree_head_symref(const char *oldref, const char *newref,
684 const char *logmsg)
685 {
686 int ret = 0;
687 struct worktree **worktrees = get_worktrees();
688 int i;
689
690 for (i = 0; worktrees[i]; i++) {
691 struct ref_store *refs;
692
693 if (worktrees[i]->is_detached)
694 continue;
695 if (!worktrees[i]->head_ref)
696 continue;
697 if (strcmp(oldref, worktrees[i]->head_ref))
698 continue;
699
700 refs = get_worktree_ref_store(worktrees[i]);
701 if (refs_create_symref(refs, "HEAD", newref, logmsg))
702 ret = error(_("HEAD of working tree %s is not updated"),
703 worktrees[i]->path);
704 }
705
706 free_worktrees(worktrees);
707 return ret;
708 }