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 /src | |
parent | 910cd2daa6af0f3af97d283eb4c6a0452688d067 (diff) | |
download | libgit2-rb/attr-with-bare.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 'src')
-rw-r--r-- | src/attr.c | 2 | ||||
-rw-r--r-- | src/repository.c | 26 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/attr.c b/src/attr.c index 05b0c1b3c..1decb5ba8 100644 --- a/src/attr.c +++ b/src/attr.c @@ -426,6 +426,8 @@ static int collect_attr_files( error = git_path_dirname_r(&dir, path); if (error < 0) goto cleanup; + if (dir.size == 1 && dir.ptr[0] == '.') + git_buf_clear(&dir); /* in precendence order highest to lowest: * - $GIT_DIR/info/attributes diff --git a/src/repository.c b/src/repository.c index d86d8905a..39a4f02b9 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1681,6 +1681,32 @@ int git_repository_is_bare(git_repository *repo) return repo->is_bare; } +int git_repository_set_bare(git_repository *repo) +{ + int error; + git_config *config; + + assert(repo); + + if (repo->is_bare) + return 0; + + if ((error = git_repository_config__weakptr(&config, repo)) < 0 || + (error = git_config_set_bool(config, "core.bare", false)) < 0) + goto done; + + error = git_config__update_entry(config, "core.worktree", NULL, true, true); + + git__free(repo->workdir); + repo->workdir = NULL; + + repo->is_bare = 1; + +done: + git_config_free(config); + return error; +} + int git_repository_head_tree(git_tree **tree, git_repository *repo) { git_reference *head; |