Changes from v2: - is_shared_symref() is introduced in its own commit - code style fixes Rubén Justo (4): worktree: introduce is_shared_symref() branch: fix die_if_checked_out() when ignore_current_worktree rebase: refuse to switch to a branch already checked out elsewhere (test) switch: reject if the branch is already checked out elsewhere (test) branch.c | 14 +++++++---- t/t2060-switch.sh | 29 ++++++++++++++++++++++ t/t3400-rebase.sh | 14 +++++++++++ worktree.c | 63 +++++++++++++++++++++++------------------------ worktree.h | 6 +++++ 5 files changed, 89 insertions(+), 37 deletions(-) Range-diff against v2: 1: cacdc022f8 < -: ---------- branch: fix die_if_checked_out() when ignore_current_worktree -: ---------- > 1: 6bbe05f452 worktree: introduce is_shared_symref() -: ---------- > 2: d787afe77f branch: fix die_if_checked_out() when ignore_current_worktree 2: 6e9ed45f4e = 3: 4c418d37f8 rebase: refuse to switch to a branch already checked out elsewhere (test) 3: a66e58e7b2 = 4: 00b075af6a switch: reject if the branch is already checked out elsewhere (test) Diff against v2: diff --git a/branch.c b/branch.c index aa854fa65f..64b7dbfd17 100644 --- a/branch.c +++ b/branch.c @@ -820,10 +820,8 @@ void remove_branch_state(struct repository *r, int verbose) void die_if_checked_out(const char *branch, int ignore_current_worktree) { struct worktree **worktrees = get_worktrees(); - int i; - for (i = 0; worktrees[i]; i++) - { + for (int i = 0; worktrees[i]; i++) { if (worktrees[i]->is_current && ignore_current_worktree) continue; diff --git a/worktree.c b/worktree.c index d500d69e4c..34043d8fe0 100644 --- a/worktree.c +++ b/worktree.c @@ -434,17 +434,12 @@ const struct worktree *find_shared_symref(struct worktree **worktrees, const char *symref, const char *target) { - const struct worktree *existing = NULL; - int i = 0; - for (i = 0; worktrees[i]; i++) { - if (is_shared_symref(worktrees[i], symref, target)) { - existing = worktrees[i]; - break; - } - } + for (int i = 0; worktrees[i]; i++) + if (is_shared_symref(worktrees[i], symref, target)) + return worktrees[i]; - return existing; + return NULL; } int submodule_uses_worktrees(const char *path) -- 2.39.0