Skip to content

Commit ac5fd29

Browse files
committed
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
2 parents 362f695 + a3a7f20 commit ac5fd29

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

refs/files-backend.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,6 +2760,8 @@ static void files_transaction_cleanup(struct files_ref_store *refs,
27602760

27612761
if (lock) {
27622762
unlock_ref(lock);
2763+
try_remove_empty_parents(refs, update->refname,
2764+
REMOVE_EMPTY_PARENTS_REF);
27632765
update->backend_data = NULL;
27642766
}
27652767
}

t/t1400-update-ref.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,4 +2349,23 @@ test_expect_success 'update-ref should also create reflog for HEAD' '
23492349
test_cmp expect actual
23502350
'
23512351

2352+
test_expect_success REFFILES 'empty directories are pruned when aborting a transaction' '
2353+
test_path_is_missing .git/refs/heads/nested &&
2354+
git update-ref --stdin <<-EOF &&
2355+
create refs/heads/nested/something HEAD
2356+
prepare
2357+
abort
2358+
EOF
2359+
test_path_is_missing .git/refs/heads/nested
2360+
'
2361+
2362+
test_expect_success REFFILES 'empty directories are pruned when not committing' '
2363+
test_path_is_missing .git/refs/heads/nested &&
2364+
git update-ref --stdin <<-EOF &&
2365+
create refs/heads/nested/something HEAD
2366+
prepare
2367+
EOF
2368+
test_path_is_missing .git/refs/heads/nested
2369+
'
2370+
23522371
test_done

0 commit comments

Comments
 (0)