Commit 5cf9875a by Russell Belfer

Add index updating to checkout

Make checkout update entries in the index for all files that are
updated and/or removed, unless flag GIT_CHECKOUT_DONT_UPDATE_INDEX
is given.  To do this, iterators were extended to allow a little
more introspection into the index being iterated over, etc.
parent 7e5c8a5b
......@@ -140,8 +140,11 @@ typedef enum {
/** Only update existing files, don't create new ones */
GIT_CHECKOUT_UPDATE_ONLY = (1u << 7),
/** Normally checkout updates index entries as it goes; this stops that */
GIT_CHECKOUT_DONT_UPDATE_INDEX = (1u << 8),
/** Don't refresh index/config/etc before doing checkout */
GIT_CHECKOUT_NO_REFRESH = (1u << 8),
GIT_CHECKOUT_NO_REFRESH = (1u << 9),
/**
* THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
......
......@@ -988,6 +988,33 @@ fail:
return -1;
}
git_index *git_iterator_index_get_index(git_iterator *iter)
{
if (iter->type == GIT_ITERATOR_SPOOLANDSORT)
iter = ((spoolandsort_iterator *)iter)->wrapped;
if (iter->type == GIT_ITERATOR_INDEX)
return ((index_iterator *)iter)->index;
return NULL;
}
git_iterator_type_t git_iterator_inner_type(git_iterator *iter)
{
if (iter->type == GIT_ITERATOR_SPOOLANDSORT)
iter = ((spoolandsort_iterator *)iter)->wrapped;
return iter->type;
}
git_iterator *git_iterator_spoolandsort_inner_iterator(git_iterator *iter)
{
if (iter->type == GIT_ITERATOR_SPOOLANDSORT)
return ((spoolandsort_iterator *)iter)->wrapped;
return NULL;
}
int git_iterator_current_tree_entry(
git_iterator *iter, const git_tree_entry **tree_entry)
{
......
......@@ -193,4 +193,12 @@ extern int git_iterator_cmp(
extern int git_iterator_current_workdir_path(
git_iterator *iter, git_buf **path);
extern git_index *git_iterator_index_get_index(git_iterator *iter);
extern git_iterator_type_t git_iterator_inner_type(git_iterator *iter);
extern git_iterator *git_iterator_spoolandsort_inner_iterator(
git_iterator *iter);
#endif
......@@ -50,28 +50,29 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
void test_checkout_tree__can_checkout_and_remove_directory(void)
{
git_reference *head;
cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
// Checkout brach "subtrees" and update HEAD, so that HEAD matches the current working tree
/* Checkout brach "subtrees" and update HEAD, so that HEAD matches the
* current working tree
*/
cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_git_pass(git_reference_symbolic_set_target(head, "refs/heads/subtrees"));
git_reference_free(head);
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert_equal_i(true, git_path_isdir("./testrepo/ab/"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
// Checkout brach "master" and update HEAD, so that HEAD matches the current working tree
/* Checkout brach "master" and update HEAD, so that HEAD matches the
* current working tree
*/
cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_git_pass(git_reference_symbolic_set_target(head, "refs/heads/master"));
git_reference_free(head);
// This directory should no longer exist
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
/* This directory should no longer exist */
cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment