mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 01:58:32 +00:00
diff: workdir diffing in a bare repo returns EBAREREPO
This commit is contained in:
parent
502be5ff3f
commit
c2e43fb1f2
16
src/diff.c
16
src/diff.c
@ -933,12 +933,14 @@ int git_diff_workdir_to_index(
|
|||||||
git_diff_list **diff)
|
git_diff_list **diff)
|
||||||
{
|
{
|
||||||
git_iterator *a = NULL, *b = NULL;
|
git_iterator *a = NULL, *b = NULL;
|
||||||
|
int error;
|
||||||
|
|
||||||
char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
|
char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
|
||||||
|
|
||||||
assert(repo && diff);
|
assert(repo && diff);
|
||||||
|
|
||||||
if (git_iterator_for_index_range(&a, repo, prefix, prefix) < 0 ||
|
if ((error = git_iterator_for_index_range(&a, repo, prefix, prefix)) < 0 ||
|
||||||
git_iterator_for_workdir_range(&b, repo, prefix, prefix) < 0)
|
(error = git_iterator_for_workdir_range(&b, repo, prefix, prefix)) < 0)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
git__free(prefix);
|
git__free(prefix);
|
||||||
@ -948,7 +950,7 @@ int git_diff_workdir_to_index(
|
|||||||
on_error:
|
on_error:
|
||||||
git__free(prefix);
|
git__free(prefix);
|
||||||
git_iterator_free(a);
|
git_iterator_free(a);
|
||||||
return -1;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -959,12 +961,14 @@ int git_diff_workdir_to_tree(
|
|||||||
git_diff_list **diff)
|
git_diff_list **diff)
|
||||||
{
|
{
|
||||||
git_iterator *a = NULL, *b = NULL;
|
git_iterator *a = NULL, *b = NULL;
|
||||||
|
int error;
|
||||||
|
|
||||||
char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
|
char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
|
||||||
|
|
||||||
assert(repo && old_tree && diff);
|
assert(repo && old_tree && diff);
|
||||||
|
|
||||||
if (git_iterator_for_tree_range(&a, repo, old_tree, prefix, prefix) < 0 ||
|
if ((error = git_iterator_for_tree_range(&a, repo, old_tree, prefix, prefix)) < 0 ||
|
||||||
git_iterator_for_workdir_range(&b, repo, prefix, prefix) < 0)
|
(error = git_iterator_for_workdir_range(&b, repo, prefix, prefix)) < 0)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
git__free(prefix);
|
git__free(prefix);
|
||||||
@ -974,7 +978,7 @@ int git_diff_workdir_to_tree(
|
|||||||
on_error:
|
on_error:
|
||||||
git__free(prefix);
|
git__free(prefix);
|
||||||
git_iterator_free(a);
|
git_iterator_free(a);
|
||||||
return -1;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "clar_libgit2.h"
|
#include "clar_libgit2.h"
|
||||||
#include "diff_helpers.h"
|
#include "diff_helpers.h"
|
||||||
|
#include "repository.h"
|
||||||
|
|
||||||
static git_repository *g_repo = NULL;
|
static git_repository *g_repo = NULL;
|
||||||
|
|
||||||
@ -818,3 +819,19 @@ void test_diff_workdir__submodules(void)
|
|||||||
git_diff_list_free(diff);
|
git_diff_list_free(diff);
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
|
||||||
|
{
|
||||||
|
git_diff_options opts = {0};
|
||||||
|
git_diff_list *diff = NULL;
|
||||||
|
git_tree *tree;
|
||||||
|
|
||||||
|
g_repo = cl_git_sandbox_init("testrepo.git");
|
||||||
|
|
||||||
|
cl_assert_equal_i(GIT_EBAREREPO, git_diff_workdir_to_index(g_repo, &opts, &diff));
|
||||||
|
|
||||||
|
cl_git_pass(git_repository_head_tree(&tree, g_repo));
|
||||||
|
cl_assert_equal_i(GIT_EBAREREPO, git_diff_workdir_to_tree(g_repo, &opts, tree, &diff));
|
||||||
|
|
||||||
|
git_tree_free(tree);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user