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

Function lock_worktree

builtin/worktree.c:1133–1170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1131}
1132
1133static 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
1172static int unlock_worktree(int ac, const char **av, const char *prefix,
1173 struct repository *repo UNUSED)

Callers

nothing calls this directly

Calls 10

parse_optionsFunction · 0.85
usage_with_optionsFunction · 0.85
get_worktreesFunction · 0.85
find_worktreeFunction · 0.85
is_main_worktreeFunction · 0.85
worktree_lock_reasonFunction · 0.85
repo_common_pathFunction · 0.85
write_fileFunction · 0.85
free_worktreesFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected