diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-07-16 09:42:27 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-07-16 09:42:27 -0700 |
| commit | ac5fd295819b0c4b4e743f522de76c482e7e7e3c (patch) | |
| tree | 5eefa4b21fa0340ba22d4469839f4f6839d4fd57 | |
| parent | Merge branch 'ps/t1006-tap-fix' (diff) | |
| parent | refs/files: remove empty parent dirs when ref creation fails (diff) | |
| download | git-ac5fd295819b0c4b4e743f522de76c482e7e7e3c.tar.gz git-ac5fd295819b0c4b4e743f522de76c482e7e7e3c.zip | |
Merge branch 'ps/refs-files-remove-empty-parent'
When a ref creation at refs/heads/foo/bar fails, the files backend
now removes refs/heads/foo/ if the directory is otherwise not used.
* ps/refs-files-remove-empty-parent:
refs/files: remove empty parent dirs when ref creation fails
| -rw-r--r-- | refs/files-backend.c | 2 | ||||
| -rwxr-xr-x | t/t1400-update-ref.sh | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c index 92c3d2c318..89ae4517a9 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2760,6 +2760,8 @@ static void files_transaction_cleanup(struct files_ref_store *refs, if (lock) { unlock_ref(lock); + try_remove_empty_parents(refs, update->refname, + REMOVE_EMPTY_PARENTS_REF); update->backend_data = NULL; } } diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 7359af02a2..96648a6e5d 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -2349,4 +2349,23 @@ test_expect_success 'update-ref should also create reflog for HEAD' ' test_cmp expect actual ' +test_expect_success REFFILES 'empty directories are pruned when aborting a transaction' ' + test_path_is_missing .git/refs/heads/nested && + git update-ref --stdin <<-EOF && + create refs/heads/nested/something HEAD + prepare + abort + EOF + test_path_is_missing .git/refs/heads/nested +' + +test_expect_success REFFILES 'empty directories are pruned when not committing' ' + test_path_is_missing .git/refs/heads/nested && + git update-ref --stdin <<-EOF && + create refs/heads/nested/something HEAD + prepare + EOF + test_path_is_missing .git/refs/heads/nested +' + test_done |
