···27012701 if (is_packed_transaction_needed(refs->packed_ref_store,
27022702 packed_transaction)) {
27032703 ret = ref_transaction_prepare(packed_transaction, err);
27042704+ /*
27052705+ * A failure during the prepare step will abort
27062706+ * itself, but not free. Do that now, and disconnect
27072707+ * from the files_transaction so it does not try to
27082708+ * abort us when we hit the cleanup code below.
27092709+ */
27102710+ if (ret) {
27112711+ ref_transaction_free(packed_transaction);
27122712+ backend_data->packed_transaction = NULL;
27132713+ }
27042714 } else {
27052715 /*
27062716 * We can skip rewriting the `packed-refs`
27072717 * file. But we do need to leave it locked, so
27082718 * that somebody else doesn't pack a reference
27092719 * that we are trying to delete.
27202720+ *
27212721+ * We need to disconnect our transaction from
27222722+ * backend_data, since the abort (whether successful or
27232723+ * not) will free it.
27102724 */
27252725+ backend_data->packed_transaction = NULL;
27112726 if (ref_transaction_abort(packed_transaction, err)) {
27122727 ret = TRANSACTION_GENERIC_ERROR;
27132728 goto cleanup;
27142729 }
27152715- backend_data->packed_transaction = NULL;
27162730 }
27172731 }
27182732
+16
t/t1404-update-ref-errors.sh
···618618 test_cmp unchanged actual
619619'
620620621621+test_expect_success 'delete fails cleanly if packed-refs.new write fails' '
622622+ # Setup and expectations are similar to the test above.
623623+ prefix=refs/failed-packed-refs &&
624624+ git update-ref $prefix/foo $C &&
625625+ git pack-refs --all &&
626626+ git update-ref $prefix/foo $D &&
627627+ git for-each-ref $prefix >unchanged &&
628628+ # This should not happen in practice, but it is an easy way to get a
629629+ # reliable error (we open with create_tempfile(), which uses O_EXCL).
630630+ : >.git/packed-refs.new &&
631631+ test_when_finished "rm -f .git/packed-refs.new" &&
632632+ test_must_fail git update-ref -d $prefix/foo &&
633633+ git for-each-ref $prefix >actual &&
634634+ test_cmp unchanged actual
635635+'
636636+621637test_done