diff options
author | Russell Belfer <rb@github.com> | 2014-09-15 21:59:23 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-09-15 21:59:23 -0700 |
commit | 1fbeb2f04c9a81a0fcacee5042d9e12a1e90052b (patch) | |
tree | e988bdf1b2a488efd9310b1d50abc2b512f3df80 /tests | |
parent | 910cd2daa6af0f3af97d283eb4c6a0452688d067 (diff) | |
download | libgit2-1fbeb2f04c9a81a0fcacee5042d9e12a1e90052b.tar.gz |
Fix attribute lookup in index for bare reposrb/attr-with-bare
When using a bare repo with an index, libgit2 attempts to read
files from the index. It caches those files based on the path
to the file, specifically the path to the directory that contains
the file.
If there is no working directory, we use `git_path_dirname_r` to
get the path to the containing directory. However, for the
`.gitattributes` file in the root of the repository, this ends up
normalizing the containing path to `"."` instead of the empty
string and the lookup the `.gitattributes` data fails.
This adds a test of attribute lookups on bare repos and also
fixes the problem by simply rewriting `"."` to be `""`.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/attr/repo.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/attr/repo.c b/tests/attr/repo.c index 5e812a72b..e8b74c08c 100644 --- a/tests/attr/repo.c +++ b/tests/attr/repo.c @@ -4,6 +4,7 @@ #include "attr.h" #include "attr_expect.h" +#include "git2/sys/repository.h" static git_repository *g_repo = NULL; @@ -333,3 +334,38 @@ void test_attr_repo__staging_properly_normalizes_line_endings_according_to_gitat git_index_free(index); } + +void test_attr_repo__bare_repo_with_index(void) +{ + const char *names[4] = { "test1", "test2", "test3", "test4" }; + const char *values[4]; + git_index *index; + + cl_git_pass(git_repository_index(&index, g_repo)); + + cl_git_mkfile( + "attr/.gitattributes", + "*.txt test1 test2=foobar -test3\n" + "trial.txt -test1 test2=barfoo !test3 test4\n"); + cl_git_pass(git_index_add_bypath(index, ".gitattributes")); + git_index_free(index); + + cl_must_pass(p_unlink("attr/.gitattributes")); + cl_assert(!git_path_exists("attr/.gitattributes")); + + cl_git_pass(git_repository_set_bare(g_repo)); + + cl_git_pass(git_attr_get_many(values, g_repo, 0, "file.txt", 4, names)); + + cl_assert(GIT_ATTR_TRUE(values[0])); + cl_assert_equal_s("foobar", values[1]); + cl_assert(GIT_ATTR_FALSE(values[2])); + cl_assert(GIT_ATTR_UNSPECIFIED(values[3])); + + cl_git_pass(git_attr_get_many(values, g_repo, 0, "trial.txt", 4, names)); + + cl_assert(GIT_ATTR_FALSE(values[0])); + cl_assert_equal_s("barfoo", values[1]); + cl_assert(GIT_ATTR_UNSPECIFIED(values[2])); + cl_assert(GIT_ATTR_TRUE(values[3])); +} |