ret = NULL; /* good */
}
strbuf_release(&err);
- }
- else {
+ } else {
+ enum ref_transaction_error tx_err;
struct strbuf err = STRBUF_INIT;
if (shallow_update && si->shallow_ref[cmd->index] &&
update_shallow_ref(cmd, si)) {
goto out;
}
- if (ref_transaction_update(transaction,
- namespaced_name,
- new_oid, old_oid,
- NULL, NULL,
- 0, "push",
- &err)) {
+ tx_err = ref_transaction_update(transaction,
+ namespaced_name,
+ new_oid, old_oid,
+ NULL, NULL,
+ 0, "push",
+ &err);
+ if (tx_err) {
rp_error("%s", err.buf);
- ret = "failed to update ref";
+ if (tx_err == REF_TRANSACTION_ERROR_GENERIC)
+ ret = "failed to update ref";
+ else
+ ret = ref_transaction_error_msg(tx_err);
} else {
ret = NULL; /* good */
}
flags |= (new_oid ? REF_HAVE_NEW : 0) | (old_oid ? REF_HAVE_OLD : 0);
flags |= (new_target ? REF_HAVE_NEW : 0) | (old_target ? REF_HAVE_OLD : 0);
+ if ((flags & REF_HAVE_NEW) && !new_target && !is_null_oid(new_oid) &&
+ !(flags & REF_SKIP_OID_VERIFICATION) && !(flags & REF_LOG_ONLY)) {
+ struct object *o = parse_object(transaction->ref_store->repo, new_oid);
+
+ if (!o) {
+ strbuf_addf(err,
+ _("trying to write ref '%s' with nonexistent object %s"),
+ refname, oid_to_hex(new_oid));
+ return REF_TRANSACTION_ERROR_INVALID_NEW_VALUE;
+ }
+
+ if (o->type != OBJ_COMMIT && is_branch(refname)) {
+ strbuf_addf(err, _("trying to write non-commit object %s to branch '%s'"),
+ oid_to_hex(new_oid), refname);
+ return REF_TRANSACTION_ERROR_INVALID_NEW_VALUE;
+ }
+ }
+
ref_transaction_add_update(transaction, refname, flags,
new_oid, old_oid, new_target,
old_target, NULL, msg);
#include "../iterator.h"
#include "../dir-iterator.h"
#include "../lockfile.h"
-#include "../object.h"
#include "../path.h"
#include "../dir.h"
#include "../chdir-notify.h"
static enum ref_transaction_error write_ref_to_lockfile(struct files_ref_store *refs,
struct ref_lock *lock,
const struct object_id *oid,
- int skip_oid_verification,
struct strbuf *err);
static int commit_ref_update(struct files_ref_store *refs,
struct ref_lock *lock,
}
oidcpy(&lock->old_oid, &orig_oid);
- if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) ||
+ if (write_ref_to_lockfile(refs, lock, &orig_oid, &err) ||
commit_ref_update(refs, lock, &orig_oid, logmsg, 0, &err)) {
error("unable to write current sha1 into %s: %s", newrefname, err.buf);
strbuf_release(&err);
goto rollbacklog;
}
- if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) ||
+ if (write_ref_to_lockfile(refs, lock, &orig_oid, &err) ||
commit_ref_update(refs, lock, &orig_oid, NULL, REF_SKIP_CREATE_REFLOG, &err)) {
error("unable to write current sha1 into %s: %s", oldrefname, err.buf);
strbuf_release(&err);
static enum ref_transaction_error write_ref_to_lockfile(struct files_ref_store *refs,
struct ref_lock *lock,
const struct object_id *oid,
- int skip_oid_verification,
struct strbuf *err)
{
static char term = '\n';
- struct object *o;
int fd;
- if (!skip_oid_verification) {
- o = parse_object(refs->base.repo, oid);
- if (!o) {
- strbuf_addf(
- err,
- "trying to write ref '%s' with nonexistent object %s",
- lock->ref_name, oid_to_hex(oid));
- unlock_ref(lock);
- return REF_TRANSACTION_ERROR_INVALID_NEW_VALUE;
- }
- if (o->type != OBJ_COMMIT && is_branch(lock->ref_name)) {
- strbuf_addf(
- err,
- "trying to write non-commit object %s to branch '%s'",
- oid_to_hex(oid), lock->ref_name);
- unlock_ref(lock);
- return REF_TRANSACTION_ERROR_INVALID_NEW_VALUE;
- }
- }
fd = get_lock_file_fd(&lock->lk);
if (write_in_full(fd, oid_to_hex(oid), refs->base.repo->hash_algo->hexsz) < 0 ||
write_in_full(fd, &term, 1) < 0 ||
} else {
ret = write_ref_to_lockfile(
refs, lock, &update->new_oid,
- update->flags & REF_SKIP_OID_VERIFICATION,
err);
if (ret) {
char *write_err = strbuf_detach(err, NULL);
return 0;
}
- /* Verify that the new object ID is valid. */
- if ((u->flags & REF_HAVE_NEW) && !is_null_oid(&u->new_oid) &&
- !(u->flags & REF_SKIP_OID_VERIFICATION) &&
- !(u->flags & REF_LOG_ONLY)) {
- struct object *o = parse_object(refs->base.repo, &u->new_oid);
- if (!o) {
- strbuf_addf(err,
- _("trying to write ref '%s' with nonexistent object %s"),
- u->refname, oid_to_hex(&u->new_oid));
- return REF_TRANSACTION_ERROR_INVALID_NEW_VALUE;
- }
-
- if (o->type != OBJ_COMMIT && is_branch(u->refname)) {
- strbuf_addf(err, _("trying to write non-commit object %s to branch '%s'"),
- oid_to_hex(&u->new_oid), u->refname);
- return REF_TRANSACTION_ERROR_INVALID_NEW_VALUE;
- }
- }
-
/*
* When we update the reference that HEAD points to we enqueue
* a second log-only update for HEAD so that its reflog is