worktree: Read worktree specific reflog for HEAD Signed-off-by: Sven Strickroth <email@cs-ware.de>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index a739c43..83174e8 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1603,6 +1603,8 @@ static int create_new_reflog_file(const char *filepath)
GIT_INLINE(int) retrieve_reflog_path(git_buf *path, git_repository *repo, const char *name)
{
+ if (strcmp(name, GIT_HEAD_FILE) == 0)
+ return git_buf_join3(path, '/', repo->gitdir, GIT_REFLOG_DIR, name);
return git_buf_join3(path, '/', repo->commondir, GIT_REFLOG_DIR, name);
}
diff --git a/tests/worktree/reflog.c b/tests/worktree/reflog.c
index 6152eb3..a68e72d 100644
--- a/tests/worktree/reflog.c
+++ b/tests/worktree/reflog.c
@@ -22,6 +22,32 @@ void test_worktree_reflog__cleanup(void)
cleanup_fixture_worktree(&fixture);
}
+void test_worktree_reflog__read_worktree_HEAD(void)
+{
+ git_reflog *reflog;
+ const git_reflog_entry *entry;
+
+ cl_git_pass(git_reflog_read(&reflog, fixture.worktree, "HEAD"));
+ cl_assert_equal_i(1, git_reflog_entrycount(reflog));
+
+ entry = git_reflog_entry_byindex(reflog, 0);
+ cl_assert(entry != NULL);
+ cl_assert_equal_s("checkout: moving from 099fabac3a9ea935598528c27f866e34089c2eff to testrepo-worktree", git_reflog_entry_message(entry));
+
+ git_reflog_free(reflog);
+}
+
+void test_worktree_reflog__read_parent_HEAD(void)
+{
+ git_reflog *reflog;
+
+ cl_git_pass(git_reflog_read(&reflog, fixture.repo, "HEAD"));
+ /* there is no logs/HEAD in the parent repo */
+ cl_assert_equal_i(0, git_reflog_entrycount(reflog));
+
+ git_reflog_free(reflog);
+}
+
void test_worktree_reflog__read(void)
{
git_reflog *reflog;