Merge branch 'nd/worktree-various-heads'
The experimental "multiple worktree" feature gains more safety to forbid operations on a branch that is checked out or being actively worked on elsewhere, by noticing that e.g. it is being rebased. * nd/worktree-various-heads: branch: do not rename a branch under bisect or rebase worktree.c: check whether branch is bisected in another worktree wt-status.c: split bisect detection out of wt_status_get_state() worktree.c: check whether branch is rebased in another worktree worktree.c: avoid referencing to worktrees[i] multiple times wt-status.c: make wt_status_check_rebase() work on any worktree wt-status.c: split rebase detection out of wt_status_get_state() path.c: refactor and add worktree_git_path() worktree.c: mark current worktree worktree.c: make find_shared_symref() return struct worktree * worktree.c: store "id" instead of "git_dir" path.c: add git_common_path() and strbuf_git_common_path() dir.c: rename str(n)cmp_icase to fspath(n)cmp
This commit is contained in:
@ -220,12 +220,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
|
||||
name = mkpathdup(fmt, bname.buf);
|
||||
|
||||
if (kinds == FILTER_REFS_BRANCHES) {
|
||||
char *worktree = find_shared_symref("HEAD", name);
|
||||
if (worktree) {
|
||||
const struct worktree *wt =
|
||||
find_shared_symref("HEAD", name);
|
||||
if (wt) {
|
||||
error(_("Cannot delete branch '%s' "
|
||||
"checked out at '%s'"),
|
||||
bname.buf, worktree);
|
||||
free(worktree);
|
||||
bname.buf, wt->path);
|
||||
ret = 1;
|
||||
continue;
|
||||
}
|
||||
@ -526,6 +526,29 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
|
||||
ref_array_clear(&array);
|
||||
}
|
||||
|
||||
static void reject_rebase_or_bisect_branch(const char *target)
|
||||
{
|
||||
struct worktree **worktrees = get_worktrees();
|
||||
int i;
|
||||
|
||||
for (i = 0; worktrees[i]; i++) {
|
||||
struct worktree *wt = worktrees[i];
|
||||
|
||||
if (!wt->is_detached)
|
||||
continue;
|
||||
|
||||
if (is_worktree_being_rebased(wt, target))
|
||||
die(_("Branch %s is being rebased at %s"),
|
||||
target, wt->path);
|
||||
|
||||
if (is_worktree_being_bisected(wt, target))
|
||||
die(_("Branch %s is being bisected at %s"),
|
||||
target, wt->path);
|
||||
}
|
||||
|
||||
free_worktrees(worktrees);
|
||||
}
|
||||
|
||||
static void rename_branch(const char *oldname, const char *newname, int force)
|
||||
{
|
||||
struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
|
||||
@ -555,6 +578,8 @@ static void rename_branch(const char *oldname, const char *newname, int force)
|
||||
|
||||
validate_new_branchname(newname, &newref, force, clobber_head_ok);
|
||||
|
||||
reject_rebase_or_bisect_branch(oldref.buf);
|
||||
|
||||
strbuf_addf(&logmsg, "Branch: renamed %s to %s",
|
||||
oldref.buf, newref.buf);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user