| 1131 | } |
| 1132 | |
| 1133 | static int lock_worktree(int ac, const char **av, const char *prefix, |
| 1134 | struct repository *repo UNUSED) |
| 1135 | { |
| 1136 | const char *reason = "", *old_reason; |
| 1137 | struct option options[] = { |
| 1138 | OPT_STRING(0, "reason", &reason, N_("string"), |
| 1139 | N_("reason for locking")), |
| 1140 | OPT_END() |
| 1141 | }; |
| 1142 | struct worktree **worktrees, *wt; |
| 1143 | char *path; |
| 1144 | |
| 1145 | ac = parse_options(ac, av, prefix, options, git_worktree_lock_usage, 0); |
| 1146 | if (ac != 1) |
| 1147 | usage_with_options(git_worktree_lock_usage, options); |
| 1148 | |
| 1149 | worktrees = get_worktrees(); |
| 1150 | wt = find_worktree(worktrees, prefix, av[0]); |
| 1151 | if (!wt) |
| 1152 | die(_("'%s' is not a working tree"), av[0]); |
| 1153 | if (is_main_worktree(wt)) |
| 1154 | die(_("The main working tree cannot be locked or unlocked")); |
| 1155 | |
| 1156 | old_reason = worktree_lock_reason(wt); |
| 1157 | if (old_reason) { |
| 1158 | if (*old_reason) |
| 1159 | die(_("'%s' is already locked, reason: %s"), |
| 1160 | av[0], old_reason); |
| 1161 | die(_("'%s' is already locked"), av[0]); |
| 1162 | } |
| 1163 | |
| 1164 | path = repo_common_path(the_repository, "worktrees/%s/locked", wt->id); |
| 1165 | write_file(path, "%s", reason); |
| 1166 | |
| 1167 | free_worktrees(worktrees); |
| 1168 | free(path); |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | static int unlock_worktree(int ac, const char **av, const char *prefix, |
| 1173 | struct repository *repo UNUSED) |
nothing calls this directly
no test coverage detected