diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-11-06 16:16:46 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-11-07 08:33:27 +0100 |
commit | 62a617dc683c1e73eebd0e1b6209f76748e67ed4 (patch) | |
tree | 5893fe2b801d96825582d8a461b50e80f4a2a43a /src/checkout.c | |
parent | f1a7906fdf0657fba88449bdab07237847f36670 (diff) | |
download | libgit2-cmn/submodule-and-dir.tar.gz |
iterator: submodules are determined by an index or treecmn/submodule-and-dir
We cannot know from looking at .gitmodules whether a directory is a
submodule or not. We need the index or tree we are comparing against to
tell us. Otherwise we have to assume the entry in .gitmodules is stale
or otherwise invalid.
Thus we pass the index of the repository into the workdir iterator, even
if we do not want to compare against it. This follows what git does,
which even for `git diff <tree>`, it will consider staged submodules as
such.
Diffstat (limited to 'src/checkout.c')
-rw-r--r-- | src/checkout.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/checkout.c b/src/checkout.c index 8203c39ea..44e2f3b27 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -2242,6 +2242,7 @@ cleanup: int git_checkout_iterator( git_iterator *target, + git_index *index, const git_checkout_options *opts) { int error = 0; @@ -2278,7 +2279,7 @@ int git_checkout_iterator( if ((error = git_iterator_reset(target, data.pfx, data.pfx)) < 0 || (error = git_iterator_for_workdir_ext( - &workdir, data.repo, data.opts.target_directory, + &workdir, data.repo, data.opts.target_directory, index, NULL, iterflags | GIT_ITERATOR_DONT_AUTOEXPAND, data.pfx, data.pfx)) < 0 || (error = git_iterator_for_tree( @@ -2388,7 +2389,7 @@ int git_checkout_index( GIT_REFCOUNT_INC(index); if (!(error = git_iterator_for_index(&index_i, index, 0, NULL, NULL))) - error = git_checkout_iterator(index_i, opts); + error = git_checkout_iterator(index_i, index, opts); if (owned) GIT_REFCOUNT_OWN(index, NULL); @@ -2405,6 +2406,7 @@ int git_checkout_tree( const git_checkout_options *opts) { int error; + git_index *index; git_tree *tree = NULL; git_iterator *tree_i = NULL; @@ -2439,10 +2441,14 @@ int git_checkout_tree( } } + if ((error = git_repository_index(&index, repo)) < 0) + return error; + if (!(error = git_iterator_for_tree(&tree_i, tree, 0, NULL, NULL))) - error = git_checkout_iterator(tree_i, opts); + error = git_checkout_iterator(tree_i, index, opts); git_iterator_free(tree_i); + git_index_free(index); git_tree_free(tree); return error; |