Merge branch 'ap/git-svn-propset-doc'
[gitweb.git] / branch.c
index 416244370783adcd7648ae7c03c7d0d8cf778b12..a5a8dcbd0ed929d09a73674361ee1dd81dd5b88c 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -334,15 +334,16 @@ void remove_branch_state(void)
        unlink(git_path_squash_msg());
 }
 
-void die_if_checked_out(const char *branch)
+void die_if_checked_out(const char *branch, int ignore_current_worktree)
 {
-       char *existing;
+       const struct worktree *wt;
 
-       existing = find_shared_symref("HEAD", branch);
-       if (existing) {
-               skip_prefix(branch, "refs/heads/", &branch);
-               die(_("'%s' is already checked out at '%s'"), branch, existing);
-       }
+       wt = find_shared_symref("HEAD", branch);
+       if (!wt || (ignore_current_worktree && wt->is_current))
+               return;
+       skip_prefix(branch, "refs/heads/", &branch);
+       die(_("'%s' is already checked out at '%s'"),
+           branch, wt->path);
 }
 
 int replace_each_worktree_head_symref(const char *oldref, const char *newref)
@@ -357,7 +358,8 @@ int replace_each_worktree_head_symref(const char *oldref, const char *newref)
                if (strcmp(oldref, worktrees[i]->head_ref))
                        continue;
 
-               if (set_worktree_head_symref(worktrees[i]->git_dir, newref)) {
+               if (set_worktree_head_symref(get_worktree_git_dir(worktrees[i]),
+                                            newref)) {
                        ret = -1;
                        error(_("HEAD of working tree %s is not updated"),
                              worktrees[i]->path);