Skip to content

Commit e940302

Browse files
committed
refdb: look for reflog in commondir
1 parent e0a6c28 commit e940302

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/refdb_fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ static int create_new_reflog_file(const char *filepath)
15821582

15831583
GIT_INLINE(int) retrieve_reflog_path(git_buf *path, git_repository *repo, const char *name)
15841584
{
1585-
return git_buf_join3(path, '/', repo->path_repository, GIT_REFLOG_DIR, name);
1585+
return git_buf_join3(path, '/', repo->commondir, GIT_REFLOG_DIR, name);
15861586
}
15871587

15881588
static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *name)

tests/worktree/reflog.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "clar_libgit2.h"
2+
#include "worktree_helpers.h"
3+
4+
#include "reflog.h"
5+
6+
#define COMMON_REPO "testrepo"
7+
#define WORKTREE_REPO "testrepo-worktree"
8+
9+
#define REFLOG "refs/heads/testrepo-worktree"
10+
#define REFLOG_MESSAGE "reflog message"
11+
12+
static worktree_fixture fixture =
13+
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
14+
15+
void test_worktree_reflog__initialize(void)
16+
{
17+
setup_fixture_worktree(&fixture);
18+
}
19+
20+
void test_worktree_reflog__cleanup(void)
21+
{
22+
cleanup_fixture_worktree(&fixture);
23+
}
24+
25+
void test_worktree_reflog__read(void)
26+
{
27+
git_reflog *reflog;
28+
const git_reflog_entry *entry;
29+
30+
cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG));
31+
cl_assert_equal_i(git_reflog_entrycount(reflog), 1);
32+
33+
entry = git_reflog_entry_byindex(reflog, 0);
34+
cl_assert(entry != NULL);
35+
cl_assert_equal_s(git_reflog_entry_message(entry), "branch: Created from HEAD");
36+
37+
git_reflog_free(reflog);
38+
}
39+
40+
void test_worktree_reflog__append_then_read(void)
41+
{
42+
git_reflog *reflog, *parent_reflog;
43+
const git_reflog_entry *entry;
44+
git_reference *head;
45+
git_signature *sig;
46+
const git_oid *oid;
47+
48+
cl_git_pass(git_repository_head(&head, fixture.worktree));
49+
cl_assert((oid = git_reference_target(head)) != NULL);
50+
cl_git_pass(git_signature_now(&sig, "foo", "foo@bar"));
51+
52+
cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG));
53+
cl_git_pass(git_reflog_append(reflog, oid, sig, REFLOG_MESSAGE));
54+
git_reflog_write(reflog);
55+
56+
cl_git_pass(git_reflog_read(&parent_reflog, fixture.repo, REFLOG));
57+
entry = git_reflog_entry_byindex(parent_reflog, 0);
58+
cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0);
59+
cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
60+
61+
git_reference_free(head);
62+
git_signature_free(sig);
63+
git_reflog_free(reflog);
64+
git_reflog_free(parent_reflog);
65+
}

0 commit comments

Comments
 (0)