t5520: test for failure if index has unresolved entries
[gitweb.git] / branch.c
index df6b1203de75618fd7aaff28f7f38ecbcd82066e..4bab55a9a85e187e2a3906312f1e771f4a214f45 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -170,7 +170,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
                const char *head;
                unsigned char sha1[20];
 
-               head = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
+               head = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
                if (!is_bare_repository() && head && !strcmp(head, ref->buf))
                        die(_("Cannot force update the current branch."));
        }
@@ -210,7 +210,6 @@ void create_branch(const char *head,
                   int force, int reflog, int clobber_head,
                   int quiet, enum branch_track track)
 {
-       struct ref_lock *lock = NULL;
        struct commit *commit;
        unsigned char sha1[20];
        char *real_ref, msg[PATH_MAX + 20];
@@ -269,15 +268,6 @@ void create_branch(const char *head,
                die(_("Not a valid branch point: '%s'."), start_name);
        hashcpy(sha1, commit->object.sha1);
 
-       if (!dont_change_ref) {
-               lock = lock_any_ref_for_update(ref.buf, NULL, 0, NULL);
-               if (!lock)
-                       die_errno(_("Failed to lock ref for update"));
-       }
-
-       if (reflog)
-               log_all_ref_updates = 1;
-
        if (forcing)
                snprintf(msg, sizeof msg, "branch: Reset to %s",
                         start_name);
@@ -285,13 +275,26 @@ void create_branch(const char *head,
                snprintf(msg, sizeof msg, "branch: Created from %s",
                         start_name);
 
+       if (reflog)
+               log_all_ref_updates = 1;
+
+       if (!dont_change_ref) {
+               struct ref_transaction *transaction;
+               struct strbuf err = STRBUF_INIT;
+
+               transaction = ref_transaction_begin(&err);
+               if (!transaction ||
+                   ref_transaction_update(transaction, ref.buf, sha1,
+                                          null_sha1, 0, !forcing, msg, &err) ||
+                   ref_transaction_commit(transaction, &err))
+                       die("%s", err.buf);
+               ref_transaction_free(transaction);
+               strbuf_release(&err);
+       }
+
        if (real_ref && track)
                setup_tracking(ref.buf + 11, real_ref, track, quiet);
 
-       if (!dont_change_ref)
-               if (write_ref_sha1(lock, sha1, msg) < 0)
-                       die_errno(_("Failed to write ref"));
-
        strbuf_release(&ref);
        free(real_ref);
 }