summaryrefslogtreecommitdiff
path: root/tests/refs
diff options
context:
space:
mode:
authorSven Strickroth <email@cs-ware.de>2018-10-05 12:47:32 +0200
committerSven Strickroth <email@cs-ware.de>2018-10-13 16:13:53 +0200
commit9f48dc3b73be1036da7b2a5a5e03346513aebf9a (patch)
tree67fcc4fcc1add48a35e04ffa7367310e40bd157b /tests/refs
parent838a2f2918b6d9fad8768d2498575ff5d75c35f0 (diff)
downloadlibgit2-9f48dc3b73be1036da7b2a5a5e03346513aebf9a.tar.gz
Remove empty directories when deleting refs
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Diffstat (limited to 'tests/refs')
-rw-r--r--tests/refs/branches/delete.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c
index 8807db231..928adf73a 100644
--- a/tests/refs/branches/delete.c
+++ b/tests/refs/branches/delete.c
@@ -2,6 +2,8 @@
#include "refs.h"
#include "repo/repo_helpers.h"
#include "config/config_helpers.h"
+#include "fileops.h"
+#include "reflog.h"
static git_repository *repo;
static git_reference *fake_remote;
@@ -140,3 +142,47 @@ void test_refs_branches_delete__removes_reflog(void)
git_reflog_free(log);
}
+void test_refs_branches_delete__removes_empty_folders(void)
+{
+ const char *commondir = git_repository_commondir(repo);
+ git_oid commit_id;
+ git_commit *commit;
+ git_reference *branch;
+
+ git_reflog *log;
+ git_oid oidzero = {{0}};
+ git_signature *sig;
+
+ git_buf ref_folder = GIT_BUF_INIT;
+ git_buf reflog_folder = GIT_BUF_INIT;
+
+ /* Create a new branch with a nested name */
+ cl_git_pass(git_oid_fromstr(&commit_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
+ cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
+ cl_git_pass(git_branch_create(&branch, repo, "some/deep/ref", commit, 0));
+ git_commit_free(commit);
+
+ /* Ensure the reflog has at least one entry */
+ cl_git_pass(git_signature_now(&sig, "Me", "user@example.com"));
+ cl_git_pass(git_reflog_read(&log, repo, "refs/heads/some/deep/ref"));
+ cl_git_pass(git_reflog_append(log, &oidzero, sig, "message"));
+ cl_assert(git_reflog_entrycount(log) > 0);
+ git_signature_free(sig);
+ git_reflog_free(log);
+
+ cl_git_pass(git_buf_joinpath(&ref_folder, commondir, "refs/heads/some/deep"));
+ cl_git_pass(git_buf_join3(&reflog_folder, '/', commondir, GIT_REFLOG_DIR, "refs/heads/some/deep"));
+
+ cl_assert(git_path_exists(git_buf_cstr(&ref_folder)) == true);
+ cl_assert(git_path_exists(git_buf_cstr(&reflog_folder)) == true);
+
+ cl_git_pass(git_branch_delete(branch));
+
+ cl_assert(git_path_exists(git_buf_cstr(&ref_folder)) == false);
+ cl_assert(git_path_exists(git_buf_cstr(&reflog_folder)) == false);
+
+ git_reference_free(branch);
+ git_buf_dispose(&ref_folder);
+ git_buf_dispose(&reflog_folder);
+}
+