Merge branch 'cc/apply'
[gitweb.git] / builtin / branch.c
index c043cfc72989bf35893d108f62cc8aa995d3a53f..8885d9f8e2cdbd6b7c3e1ff753147f57ffd37243 100644 (file)
@@ -20,6 +20,7 @@
 #include "utf8.h"
 #include "wt-status.h"
 #include "ref-filter.h"
+#include "worktree.h"
 
 static const char * const builtin_branch_usage[] = {
        N_("git branch [<options>] [-r | -a] [--merged | --no-merged]"),
@@ -215,16 +216,21 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                int flags = 0;
 
                strbuf_branchname(&bname, argv[i]);
-               if (kinds == FILTER_REFS_BRANCHES && !strcmp(head, bname.buf)) {
-                       error(_("Cannot delete the branch '%s' "
-                             "which you are currently on."), bname.buf);
-                       ret = 1;
-                       continue;
-               }
-
                free(name);
-
                name = mkpathdup(fmt, bname.buf);
+
+               if (kinds == FILTER_REFS_BRANCHES) {
+                       char *worktree = find_shared_symref("HEAD", name);
+                       if (worktree) {
+                               error(_("Cannot delete branch '%s' "
+                                       "checked out at '%s'"),
+                                     bname.buf, worktree);
+                               free(worktree);
+                               ret = 1;
+                               continue;
+                       }
+               }
+
                target = resolve_ref_unsafe(name,
                                            RESOLVE_REF_READING
                                            | RESOLVE_REF_NO_RECURSE
@@ -594,7 +600,7 @@ static int edit_branch_description(const char *branch_name)
        strbuf_stripspace(&buf, 1);
 
        strbuf_addf(&name, "branch.%s.description", branch_name);
-       git_config_set_or_die(name.buf, buf.len ? buf.buf : NULL);
+       git_config_set(name.buf, buf.len ? buf.buf : NULL);
        strbuf_release(&name);
        strbuf_release(&buf);
 
@@ -790,10 +796,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        die(_("Branch '%s' has no upstream information"), branch->name);
 
                strbuf_addf(&buf, "branch.%s.remote", branch->name);
-               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar(buf.buf, NULL, NULL, 1);
                strbuf_reset(&buf);
                strbuf_addf(&buf, "branch.%s.merge", branch->name);
-               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar(buf.buf, NULL, NULL, 1);
                strbuf_release(&buf);
        } else if (argc > 0 && argc <= 2) {
                struct branch *branch = branch_get(argv[0]);