Skip to content

Commit 6573284

Browse files
jrngitster
authored andcommitted
ref_transaction_commit: bail out on failure to remove a ref
When removal of a loose or packed ref fails, bail out instead of trying to finish the transaction. This way, a single error message can be printed (instead of multiple messages being concatenated by mistake) and the operator can try to solve the underlying problem before there is a chance to muck things up even more. In particular, when git fails to remove a ref, git goes on to try to delete the reflog. Exiting early lets us keep the reflog. When git succeeds in deleting a ref A and fails to remove a ref B, it goes on to try to delete both reflogs. It would be better to just remove the reflog for A, but that would be a more invasive change. Failing early means we keep both reflogs, which puts the operator in a good position to understand the problem and recover. A long term goal is to avoid these problems altogether and roll back the transaction on failure. That kind of transactionality will have to wait for a later series (the plan for which is to make all destructive work happen in a single update of the packed-refs file). Signed-off-by: Jonathan Nieder <[email protected]> Reviewed-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb43bd1 commit 6573284

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

refs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,16 +3809,20 @@ int ref_transaction_commit(struct ref_transaction *transaction,
38093809
struct ref_update *update = updates[i];
38103810

38113811
if (update->lock) {
3812-
if (delete_ref_loose(update->lock, update->type, err))
3812+
if (delete_ref_loose(update->lock, update->type, err)) {
38133813
ret = TRANSACTION_GENERIC_ERROR;
3814+
goto cleanup;
3815+
}
38143816

38153817
if (!(update->flags & REF_ISPRUNING))
38163818
delnames[delnum++] = update->lock->ref_name;
38173819
}
38183820
}
38193821

3820-
if (repack_without_refs(delnames, delnum, err))
3822+
if (repack_without_refs(delnames, delnum, err)) {
38213823
ret = TRANSACTION_GENERIC_ERROR;
3824+
goto cleanup;
3825+
}
38223826
for (i = 0; i < delnum; i++)
38233827
unlink_or_warn(git_path("logs/%s", delnames[i]));
38243828
clear_loose_ref_cache(&ref_cache);

0 commit comments

Comments
 (0)