Skip to content

Commit eb0a3af

Browse files
committed
worktree: Read worktree specific reflog for HEAD
Signed-off-by: Sven Strickroth <email@cs-ware.de>
1 parent 2a11eaf commit eb0a3af

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/refdb_fs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,8 @@ static int create_new_reflog_file(const char *filepath)
16031603

16041604
GIT_INLINE(int) retrieve_reflog_path(git_buf *path, git_repository *repo, const char *name)
16051605
{
1606+
if (strcmp(name, GIT_HEAD_FILE) == 0)
1607+
return git_buf_join3(path, '/', repo->gitdir, GIT_REFLOG_DIR, name);
16061608
return git_buf_join3(path, '/', repo->commondir, GIT_REFLOG_DIR, name);
16071609
}
16081610

tests/worktree/reflog.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ void test_worktree_reflog__cleanup(void)
2222
cleanup_fixture_worktree(&fixture);
2323
}
2424

25+
void test_worktree_reflog__read_worktree_HEAD(void)
26+
{
27+
git_reflog *reflog;
28+
const git_reflog_entry *entry;
29+
30+
cl_git_pass(git_reflog_read(&reflog, fixture.worktree, "HEAD"));
31+
cl_assert_equal_i(1, git_reflog_entrycount(reflog));
32+
33+
entry = git_reflog_entry_byindex(reflog, 0);
34+
cl_assert(entry != NULL);
35+
cl_assert_equal_s("checkout: moving from 099fabac3a9ea935598528c27f866e34089c2eff to testrepo-worktree", git_reflog_entry_message(entry));
36+
37+
git_reflog_free(reflog);
38+
}
39+
40+
void test_worktree_reflog__read_parent_HEAD(void)
41+
{
42+
git_reflog *reflog;
43+
44+
cl_git_pass(git_reflog_read(&reflog, fixture.repo, "HEAD"));
45+
/* there is no logs/HEAD in the parent repo */
46+
cl_assert_equal_i(0, git_reflog_entrycount(reflog));
47+
48+
git_reflog_free(reflog);
49+
}
50+
2551
void test_worktree_reflog__read(void)
2652
{
2753
git_reflog *reflog;

0 commit comments

Comments
 (0)