verify_packfile: check pack validity before accessing data
[gitweb.git] / branch.c
index 713ceda36a900b88435528bff7d2d423c89bb00b..416244370783adcd7648ae7c03c7d0d8cf778b12 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -70,18 +70,18 @@ int install_branch_config(int flag, const char *local, const char *origin, const
        }
 
        strbuf_addf(&key, "branch.%s.remote", local);
-       if (git_config_set(key.buf, origin ? origin : ".") < 0)
+       if (git_config_set_gently(key.buf, origin ? origin : ".") < 0)
                goto out_err;
 
        strbuf_reset(&key);
        strbuf_addf(&key, "branch.%s.merge", local);
-       if (git_config_set(key.buf, remote) < 0)
+       if (git_config_set_gently(key.buf, remote) < 0)
                goto out_err;
 
        if (rebasing) {
                strbuf_reset(&key);
                strbuf_addf(&key, "branch.%s.rebase", local);
-               if (git_config_set(key.buf, "true") < 0)
+               if (git_config_set_gently(key.buf, "true") < 0)
                        goto out_err;
        }
        strbuf_release(&key);
@@ -344,3 +344,26 @@ void die_if_checked_out(const char *branch)
                die(_("'%s' is already checked out at '%s'"), branch, existing);
        }
 }
+
+int replace_each_worktree_head_symref(const char *oldref, const char *newref)
+{
+       int ret = 0;
+       struct worktree **worktrees = get_worktrees();
+       int i;
+
+       for (i = 0; worktrees[i]; i++) {
+               if (worktrees[i]->is_detached)
+                       continue;
+               if (strcmp(oldref, worktrees[i]->head_ref))
+                       continue;
+
+               if (set_worktree_head_symref(worktrees[i]->git_dir, newref)) {
+                       ret = -1;
+                       error(_("HEAD of working tree %s is not updated"),
+                             worktrees[i]->path);
+               }
+       }
+
+       free_worktrees(worktrees);
+       return ret;
+}